#pragma once #include #include #include #include #define NK_INCLUDE_FIXED_TYPES #define NK_INCLUDE_STANDARD_IO #define NK_INCLUDE_STANDARD_VARARGS #define NK_INCLUDE_DEFAULT_ALLOCATOR #define NK_INCLUDE_VERTEX_BUFFER_OUTPUT #define NK_INCLUDE_FONT_BAKING #define NK_INCLUDE_DEFAULT_FONT #include #include #include #include #include #include #include namespace Artifact { namespace Events { struct PipelineReload {}; struct DrawUI { nk_context* ctx; }; } /* class Engine: public EventTarget { public: // Windowing int viewportWidth = 1200; int viewportHeight = 800; GLFWwindow* window = []{ glfwInit(); glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); auto w = glfwCreateWindow(1200, 800, "Artifact Engine", nullptr, nullptr); if (!w) throw std::runtime_error("Failed to create GLFW window"); glfwShowWindow(w); glfwPollEvents(); return w; }(); WGPUInstance instance = nullptr; WGPUAdapter adapter = nullptr; WGPUDevice device = nullptr; WGPUSurface surface = nullptr; WGPUTextureFormat surfaceFormat = WGPUTextureFormat_BGRA8Unorm; WGPUQueue queue = nullptr; WGPURenderPipeline worldPipeline = nullptr; WGPURenderPipeline objectPipeline = nullptr; WGPURenderPipeline uiPipeline = nullptr; std::unique_ptr depthTexture; std::unique_ptr world; std::string assetPath = std::string(getenv("HOME")) + "/eclipse-workspace/ArtifactEngine/assets"; Engine(); ~Engine(); void init(); void run(); }; /*/ // Forward declaration. class Server; class Engine: public EventTarget { public: // Windowing int viewportWidth = 1200; int viewportHeight = 800; Window window; // WebGPU WGPUInstance instance = nullptr; WGPUAdapter adapter = nullptr; WGPUDevice device = nullptr; WGPUSurface surface = nullptr; WGPUTextureFormat surfaceFormat = WGPUTextureFormat_BGRA8Unorm; WGPUQueue queue = nullptr; WGPURenderPipeline worldPipeline = nullptr; WGPURenderPipeline objectPipeline = nullptr; WGPURenderPipeline uiPipeline = nullptr; std::unique_ptr depthTexture; // Nuklear std::unique_ptr ui; std::unique_ptr uiFontTexture; std::unique_ptr uiDummyTexture; nk_buffer uiVertexBufferNK; nk_buffer uiIndexBufferNK; nk_buffer uiCommandBufferNK; WGPUBuffer uiVertexBuffer = nullptr; WGPUBuffer uiIndexBuffer = nullptr; WGPUBuffer uiUniformBuffer = nullptr; WGPUSampler uiSampler = nullptr; WGPUBindGroupLayout uiBgl = nullptr; // World std::unique_ptr world; WGPUBuffer worldUniformBuffer = nullptr; WGPUSampler worldSampler = nullptr; WGPUBindGroupLayout worldBgl = nullptr; WGPUBindGroup worldBindGroup = nullptr; std::unique_ptr nodeTextureAtlas; std::unique_ptr chunkRenderer = std::make_unique(this); // Misc std::string assetPath = std::string(getenv("HOME")) + "/eclipse-workspace/ArtifactEngine/assets"; glm::mat4 ortho; Server* server = nullptr; Engine(); ~Engine(); // Initialize the engine: open the window, set up the wgpu device, etc. void init(); // Reload shaders, processing overrides if present. void reloadShaders(); // Create (and refresh) the pipelines used to render the world. void makeWorldPipelines(); // Create (and refresh) the pipeline used to render entities. void makeObjectPipeline(); // Create (and refresh) the pipeline used to render the UI. void makeUIPipeline(); // Manages the main loop. void run(); // Performs rendering per-frame. void render(); // Updates game logic per-step. void tick(); // Send a message to the server. template void sendMessage(T msg); // Receive a message from the server. template void receiveMessage(T msg) { if constexpr (std::is_same_v) { std::cout << "Message received" << std::endl; } else if constexpr (std::is_same_v) { auto ev = (Events::ChunkChanged) msg; world->chunks.emplace(ev.pos, std::make_unique(ev.data)); chunkRenderer->addChunk(ev.pos, world->chunks.at(ev.pos).get()); } } }; //*/ } #include template void Artifact::Engine::sendMessage(T msg){ if(server) { server->receiveMessage(msg); } else { //auto buffer = cista::serialize(msg); } }