Update some things.

This commit is contained in:
Signal 2026-04-06 18:30:52 -04:00
parent f215bc3742
commit f9d6e7a70a
35 changed files with 575 additions and 905 deletions

View file

@ -0,0 +1,7 @@
#include "Camera.h"
namespace Artifact {
}

24
Client/Graphics/Camera.h Normal file
View file

@ -0,0 +1,24 @@
#pragma once
#include <vector>
#include <typeindex>
#include <glm/glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
namespace Artifact {
class Camera {
public:
glm::vec3 pos;
glm::quat rot;
double fov;
float near;
float far;
std::vector<std::type_index> renderPasses;
Camera(glm::vec3 pos, double fov, float near, float far) : pos(pos), fov(fov), near(near), far(far) {}
};
}

View file

@ -8,7 +8,7 @@ namespace Artifact {
void Graphics::init() {
instance = wgpuCreateInstance(nullptr);
window = engine->subsystem<Window>();
window = client->subsystem<WindowImpl>();
surface = window->createWGPUSurface(instance);

View file

@ -3,6 +3,7 @@
#include <webgpu/webgpu.h>
#include <Shared.h>
#include "../Client.h"
#include "../Platform/Window.h"
namespace Artifact {
@ -18,7 +19,7 @@ public:
virtual void render(WGPUTextureView nextTexture, WGPUCommandEncoder encoder) {}
};
class Graphics: public BaseSubsystem, public Engine<GraphicsSubsystem> {
class Graphics: public ClientSubsystem, public Engine<GraphicsSubsystem> {
public:
WGPUInstance instance = nullptr;
WGPUSurface surface = nullptr;
@ -29,14 +30,11 @@ public:
WGPUTextureView depthTextureView = nullptr;
WGPUQueue queue = nullptr;
Window * window;
WindowImpl * window;
void init() override;
void deinit() override;
void render() override;
void onSubsystemAdd(GraphicsSubsystem * system) {
system->graphics = this;
}
WGPUTexture createTextureFromData(const void* data, uint32_t width, uint32_t height);
WGPUTexture createTextureFromFile(const char* file);

View file

@ -14,14 +14,14 @@ struct DrawUI {};
}
static std::unordered_map<Key, nk_keys> ArtifactToNuklear {};
static std::array<nk_keys, static_cast<size_t>(Key::Last) + 1> ArtifactToNuklear {};
namespace {
static struct _nkInit {
_nkInit() {
// Populate the Artifact-to-Nuklear key map.
#define X(nuklear, artifact) ArtifactToNuklear[Key::artifact] = nuklear
#define X(nuklear, artifact) ArtifactToNuklear[static_cast<int>(Key::artifact)] = nuklear
X(NK_KEY_CTRL, ControlLeft);
X(NK_KEY_CTRL, ControlRight);
@ -47,37 +47,36 @@ static struct _nkInit {
void UIRenderer::init() {
printf("UI: %p", graphics);
window = graphics->window;
window->listen<Events::InputBegin>([this](auto ev) {
graphics->window->listen<Events::InputBegin>([this](auto ev) {
nk_input_begin(&ctx);
});
window->listen<Events::InputEnd>([this](auto ev) {
graphics->window->listen<Events::InputEnd>([this](auto ev) {
nk_input_end(&ctx);
});
window->listen<Events::CursorPosEvent>([this](auto ev) {
graphics->window->listen<Events::CursorPosEvent>([this](auto ev) {
nk_input_motion(&ctx, ev.x, ev.y);
});
window->listen<Events::ScrollEvent>([this](auto ev) {
graphics->window->listen<Events::ScrollEvent>([this](auto ev) {
nk_input_scroll(&ctx, nk_vec2(ev.dx, ev.dy));
});
window->listen<Events::MouseEvent>([this](auto ev) {
graphics->window->listen<Events::MouseEvent>([this](auto ev) {
nk_input_button(&ctx, ev.button == Events::MOUSE_BUTTON_RIGHT ? NK_BUTTON_RIGHT : NK_BUTTON_LEFT, (int)ev.x, (int)ev.y, ev.state);
});
window->listen<Events::KeyDownEvent>([this](auto ev) {
nk_input_key(&ctx, ArtifactToNuklear[ev.key], true);
graphics->window->listen<Events::KeyDownEvent>([this](auto ev) {
nk_input_key(&ctx, ArtifactToNuklear[static_cast<int>(ev.key)], true);
});
window->listen<Events::KeyUpEvent>([this](auto ev) {
nk_input_key(&ctx, ArtifactToNuklear[ev.key], false);
graphics->window->listen<Events::KeyUpEvent>([this](auto ev) {
nk_input_key(&ctx, ArtifactToNuklear[static_cast<int>(ev.key)], false);
});
window->listen<Events::CharInputEvent>([this](auto ev) {
graphics->window->listen<Events::CharInputEvent>([this](auto ev) {
nk_input_char(&ctx, ev.codepoint);
});
@ -102,7 +101,6 @@ void UIRenderer::init() {
fclose(fontFile);
font = nk_font_atlas_add_from_memory(&atlas, fontData, fontSize, 13.0f, nullptr);
} else {
fprintf(stderr, (std::string("Failed to load font: ") + assetPath + "/fonts/Arial.ttf\n").c_str());
font = nk_font_atlas_add_default(&atlas, 13.0f, nullptr);
}

View file

@ -21,7 +21,6 @@ class UIRenderer: public GraphicsSubsystem, public EventTarget {
nk_font_atlas atlas {};
WGPURenderPipeline pipeline = nullptr;
Window * window = nullptr;
WGPUBuffer vertexBuffer = nullptr;
WGPUBuffer indexBuffer = nullptr;

View file

@ -1,3 +1,11 @@
#pragma once
#include <Shared.h>
namespace Artifact {
class WorldRenderer {
};
}