1
0

write shit

This commit is contained in:
2026-01-06 16:27:19 +08:00
parent 52916db08f
commit 4cdc56a32d
24 changed files with 512 additions and 135 deletions

View File

@@ -1,4 +1,4 @@
#include <basalt_export.hpp>
#include <basalt/export_macro.hpp>
BS_EXPORT void* BSCreateInstance() {
return nullptr;

View File

@@ -1,5 +1,5 @@
#include <basalt_export.hpp>
#include <engine.hpp>
#include <basalt/export_macro.hpp>
#include <basalt/kernel.hpp>
#include <windows.h>
#include <d3d11.h>
#include <d3dcompiler.h>
@@ -161,8 +161,8 @@ const char* g_PS = R"(
}
)";
using ::Basalt::Shared::Engine::EngineConfig;
using ::Basalt::Shared::Engine::IEngine;
using ::Basalt::Shared::Kernel::EngineConfig;
using ::Basalt::Shared::Kernel::IEngine;
class DirectX11Engine : public IEngine {
public:
@@ -383,9 +383,9 @@ public:
};
BS_EXPORT void* BSCreateInstance() {
return new DirectX11Engine();
return static_cast<IEngine*>(new DirectX11Engine());
}
BS_EXPORT void BSDestroyInstance(void* instance) {
delete reinterpret_cast<DirectX11Engine*>(instance);
delete dynamic_cast<DirectX11Engine*>(static_cast<IEngine*>(instance));
}

View File

@@ -54,8 +54,9 @@ namespace Basalt::Presenter {
dll_path /= filename;
#if defined(BASALT_OS_WINDOWS)
dll_path.replace_extension(BSTEXT(".dll"));
#else
dll_path.replace_extension(BSTEXT(".so"));
#endif
// Load DLL
#if defined(BASALT_OS_WINDOWS)
m_Handle = LoadLibraryW(dll_path.wstring().c_str());

View File

@@ -1,4 +1,4 @@
#include <basalt_char.hpp>
#include <basalt/char_types.hpp>
#include <string_view>
#if defined(BASALT_OS_WINDOWS)

View File

@@ -1,15 +1,17 @@
#include "dll_loader.hpp"
#include <basalt_char.hpp>
#include <engine.hpp>
#include <basalt/char_types.hpp>
#include <basalt/kernel.hpp>
namespace Presenter = ::Basalt::Presenter;
namespace Shared = ::Basalt::Shared;
namespace Kernel = ::Basalt::Shared::Kernel;
int main(int argc, char* argv[]) {
auto engine_dll = Presenter::DllLoader(Presenter::DllKind::Engine, BSTEXT("BasaltDirectX11Engine"));
auto* engine = engine_dll.CreateInstance<Shared::Engine::IEngine>();
auto deliver_dll = Presenter::DllLoader(Presenter::DllKind::Deliver, BSTEXT("BasaltPipeDeliver"));
auto* engine = engine_dll.CreateInstance<Kernel::IEngine>();
auto* deliver = deliver_dll.CreateInstance<Kernel::IDeliver>();
Shared::Engine::EngineConfig engine_config{.headless = false, .title = BSTEXT("Fuck You"), .width = 800, .height = 600};
Kernel::EngineConfig engine_config{.headless = false, .title = BSTEXT("Fuck You"), .width = 800, .height = 600};
engine->Startup(std::move(engine_config));
while (true) {

View File

@@ -0,0 +1,15 @@
# Basalt Presenter
## Dependencies
* [tinyobjloader](https://github.com/tinyobjloader/tinyobjloader)
* [cgltf](https://github.com/jkuhlmann/cgltf)
## Warning
This project was not written robustly.
So please confirm following conditions when running this program.
- ASCII-only path. It would be better to have English-chars-only path. No space, tab or weird chars.
- Not too long path. It would be better that less than 200 chars.
- ASCII-only command line arguments.

View File

@@ -2,9 +2,9 @@ add_library(BasaltShared STATIC "")
target_sources(BasaltShared
PRIVATE
# Sources
pipe_operator.cpp
engine.cpp
deliver.cpp
basalt/pipe_operator.cpp
basalt/kernel.cpp
basalt/math.cpp
)
target_sources(BasaltShared
@@ -12,11 +12,11 @@ PUBLIC
FILE_SET HEADERS
FILES
# Headers
basalt_char.hpp
basalt_export.hpp
pipe_operator.hpp
engine.hpp
deliver.hpp
basalt/char_types.hpp
basalt/export_macro.hpp
basalt/pipe_operator.hpp
basalt/kernel.hpp
basalt/math.hpp
)
target_include_directories(BasaltShared
PUBLIC

View File

@@ -1,3 +1,4 @@
#pragma once
#include <cwchar>
#include <string>
#include <string_view>

View File

@@ -0,0 +1,65 @@
#include "kernel.hpp"
#include <stdexcept>
namespace Basalt::Shared::Kernel {
#pragma region Engine
IEngine::IEngine() : config(), status(EngineStatus::Ready) {}
IEngine::~IEngine() {
if (this->status != EngineStatus::Stop) {
this->Shutdown();
}
}
Guid IEngine::GetGuid() const {
throw std::logic_error("unimplemented function");
}
void IEngine::Startup(EngineConfig &&config) {
if (this->status != EngineStatus::Ready) throw std::runtime_error("unexpected engine status");
this->config = std::move(config);
this->status = EngineStatus::Running;
}
bool IEngine::Tick() {
if (this->status != EngineStatus::Running) throw std::runtime_error("unexpected engine status");
return false;
}
void IEngine::Shutdown() {
if (this->status != EngineStatus::Running) throw std::runtime_error("unexpected engine status");
this->status = EngineStatus::Stop;
}
#pragma endregion
#pragma region Deliver
IDeliver::IDeliver() {}
IDeliver::~IDeliver() {}
Guid IDeliver::GetGuid() const {
throw std::logic_error("unimplemented function");
}
void IDeliver::Startup(DeliverConfig &&config) {
if (this->status != DeliverStatus::Ready) throw std::runtime_error("unexpected deliver status");
this->config = std::move(config);
this->status = DeliverStatus::Running;
}
void IDeliver::Transmit() {
if (this->status != DeliverStatus::Running) throw std::runtime_error("unexpected deliver status");
}
void IDeliver::Shutdown() {
if (this->status != DeliverStatus::Running) throw std::runtime_error("unexpected deliver status");
this->status = DeliverStatus::Stop;
}
#pragma endregion
} // namespace Basalt::Shared::Kernel

View File

@@ -0,0 +1,123 @@
#pragma once
#include "char_types.hpp"
#include <string>
#include <cinttypes>
namespace Basalt::Shared::Kernel {
#pragma region Guid & Predefined Guid
struct Guid {
std::uint32_t d1, d2;
constexpr Guid(std::uint32_t gd1 = 0, std::uint32_t gd2 = 0) : d1(gd1), d2(gd2) {}
Guid(const Guid& rhs) : d1(rhs.d1), d2(rhs.d2) {}
Guid(Guid&& rhs) noexcept : d1(rhs.d1), d2(rhs.d2) {}
Guid& operator=(const Guid& rhs) {
this->d1 = rhs.d1;
this->d2 = rhs.d2;
return *this;
}
Guid& operator=(Guid&& rhs) noexcept {
this->d1 = rhs.d1;
this->d2 = rhs.d2;
return *this;
}
auto operator<=>(const Guid& rhs) const {
if (auto cmp = this->d1 <=> rhs.d1; cmp != 0) return cmp;
return this->d2 <=> rhs.d2;
}
bool operator==(const Guid& rhs) const { return ((this->d1 == rhs.d1) && (this->d2 == rhs.d2)); }
};
constexpr Guid DIRECTX8_ENGINE{0x0, 0x1};
constexpr Guid DIRECTX9_ENGINE{0x0, 0x2};
constexpr Guid DIRECTX11_ENGINE{0x0, 0x3};
constexpr Guid DIRECTX12_ENGINE{0x0, 0x4};
constexpr Guid OPENGL_ENGINE{0x0, 0x5};
constexpr Guid VULKAN_ENGINE{0x0, 0x6};
constexpr Guid CUDA_DELIVER{0x1, 0x1};
constexpr Guid ROCM_DELIVER{0x1, 0x2};
constexpr Guid PIPE_DELIVER{0x1, 0x3};
constexpr Guid TCP_DELIVER{0x1, 0x4};
constexpr Guid MMAP_DELIVER{0x1, 0x5};
constexpr Guid TINYOBJLOADER_OBJECT_LOADER{0x2, 0x1};
constexpr Guid CGLTF_OBJECT_LOADER{0x2, 0x2};
constexpr Guid ASSIMP_OBJECT_LOADER{0x2, 0x3};
constexpr Guid HOMEBREW_ANIME_LOADER{0x3, 0x1};
#pragma endregion
#pragma region Engine
struct EngineConfig {
bool headless; ///< Whether enable headless mode (No Window created).
std::basic_string<BSCHAR> title; ///< Window title.
std::uint32_t width; ///< Window width.
std::uint32_t height; ///< Window height.
Guid deliver; ///< The GUID of deliver.
};
enum class EngineStatus {
Ready, ///< Engine was allocated but not initialized.
Running, ///< Engine has been initialized and running.
Stop, ///< Engine is shutdown.
};
class IEngine {
public:
IEngine();
virtual ~IEngine();
public:
virtual Guid GetGuid() const;
virtual void Startup(EngineConfig&& config);
/**
* @brief
* @return True for active exit.
*/
virtual bool Tick();
virtual void Shutdown();
protected:
EngineConfig config;
EngineStatus status;
};
#pragma endregion
#pragma region Deliver
struct DeliverConfig {
Guid engine; ///< The GUID of render engine.
};
enum class DeliverStatus {
Ready, ///< Engine was allocated but not initialized.
Running, ///< Engine has been initialized and running.
Stop, ///< Engine is shutdown.
};
class IDeliver {
public:
IDeliver();
virtual ~IDeliver();
public:
virtual Guid GetGuid() const;
virtual void Startup(DeliverConfig&& config);
virtual void Transmit();
virtual void Shutdown();
protected:
DeliverConfig config;
DeliverStatus status;
};
#pragma endregion
} // namespace Basalt::Shared::Kernel

View File

@@ -0,0 +1,5 @@
#include "math.hpp"
namespace Basalt::Shared::Math {
}

View File

@@ -0,0 +1,34 @@
#pragma once
#include <stdexcept>
namespace Basalt::Shared::Math {
using FloatPoint = float;
struct Vector3 {
FloatPoint x, y, z;
};
struct Vector4 {
FloatPoint x, y, z, w;
};
struct Matrix4x4 {
Vector4 data[4];
};
//template<typename TEle, size_t VCnt>
// requires(std::integral<TEle> || std::floating_point<TEle>)
//struct Vector {
// TEle factor[VCnt];
//};
#define NOT_IMPLEMENTED throw std::logic_error("not implemented function");
template<typename TNum, typename TVec>
struct Vector3Traits {};
template<typename TNum, typename TMat>
struct Matrix4x4Traits {};
#undef NOT_IMPLEMENTED
} // namespace Basalt::Shared::Math

View File

@@ -1,4 +1,4 @@
#include "basalt_char.hpp"
#include "char_types.hpp"
#include <string_view>
#if defined(BASALT_OS_WINDOWS)

View File

@@ -1,9 +0,0 @@
#include "deliver.hpp"
namespace Basalt::Shared::Deliver {
IDeliver::IDeliver() {}
IDeliver::~IDeliver() {}
} // namespace Basalt::Shared::Deliver

View File

@@ -1,18 +0,0 @@
#pragma once
namespace Basalt::Shared::Deliver {
struct DeliverConfig {
};
class IDeliver {
public:
IDeliver();
virtual ~IDeliver();
public:
virtual void Transmit() = 0;
};
}

View File

@@ -1,30 +0,0 @@
#include "engine.hpp"
#include <stdexcept>
namespace Basalt::Shared::Engine {
IEngine::IEngine() : config(), status(EngineStatus::Ready) {}
IEngine::~IEngine() {
if (this->status != EngineStatus::Stop) {
this->Shutdown();
}
}
void IEngine::Startup(EngineConfig &&config) {
if (this->status != EngineStatus::Ready) throw std::runtime_error("unexpected engine status");
this->config = std::move(config);
this->status = EngineStatus::Running;
}
bool IEngine::Tick() {
if (this->status != EngineStatus::Running) throw std::runtime_error("unexpected engine status");
return false;
}
void IEngine::Shutdown() {
if (this->status != EngineStatus::Running) throw std::runtime_error("unexpected engine status");
this->status = EngineStatus::Stop;
}
} // namespace Basalt::Shared::Engine

View File

@@ -1,49 +0,0 @@
#pragma once
#include "basalt_char.hpp"
#include <string>
#include <cinttypes>
namespace Basalt::Shared::Engine {
enum class EngineKind {
DirectX8,
DirectX9,
DirectX11,
DirectX12,
OpenGL,
Vulkan,
};
struct EngineConfig {
bool headless; ///< Whether enable headless mode (No Window created).
std::basic_string<BSCHAR> title; ///< Window title.
std::uint32_t width; ///< Window width.
std::uint32_t height; ///< Window height.
};
enum class EngineStatus {
Ready, ///< Engine was allocated but not initialized.
Running, ///< Engine has been initialized and running.
Stop, ///< Engine is shutdown.
};
class IEngine {
public:
IEngine();
virtual ~IEngine();
public:
virtual void Startup(EngineConfig&& config);
/**
* @brief
* @return True for active exit.
*/
virtual bool Tick();
virtual void Shutdown();
protected:
EngineConfig config;
EngineStatus status;
};
}