catcrafts.net/implementations/main.cpp

53 lines
2 KiB
C++
Raw Normal View History

2025-11-12 20:58:07 +01:00
/*
catcrafts.net
Copyright (C) 2026 Catcrafts
2025-11-12 20:58:07 +01:00
The source code of this website is made available for viewing purposes only.
2025-11-12 20:58:07 +01:00
No permission is granted to copy, modify, distribute, or create derivative works.
*/
import Catcrafts;
import Crafter.Graphics;
2025-11-12 20:58:07 +01:00
import std;
using namespace Catcrafts;
using namespace Crafter;
2025-11-12 21:24:23 +01:00
int main() {
Device::Initialize();
// Window in CRAFTER_GRAPHICS_WINDOW_DOM mode is a page-level event hub
// plus the rAF driver; even without subscribing to its events we need
// it so StartSync() can keep the wasm module alive past main() (the
// bridge stashes a raw pointer, so the storage has to outlive main).
2026-07-19 01:13:30 +02:00
// The dimensions are a hint only — the JS bridge sizes the render
// surface to the canvas (full viewport, or the mount element).
static Window window(1280, 720, "Catcrafts");
2026-08-05 04:18:37 +02:00
// document.title is only reachable through Window::SetTitle, so give the
// router a way to set a per-route title without threading a Window
// through every render call.
SetActiveWindow(&window);
2026-07-19 01:13:30 +02:00
// Build the ray-tracing pipeline + scene now (runs StartInit/FinishInit).
2026-08-05 04:18:37 +02:00
// The render canvas starts hidden; it only traces once the /demo route
2026-07-19 01:13:30 +02:00
// mounts it into #webgpu-demo (see Catcrafts:Demo).
SetupDemo(window);
InitializePage();
2026-08-05 04:18:37 +02:00
// Back/forward. The Router V1 callback carries no payload, so the route is
// re-read from window.location — which is the right thing regardless,
// since the location is the single source of truth for what should be on
// screen.
Router::AddPopStateListener([]{ RenderCurrentRoute(); });
2025-11-12 20:58:07 +01:00
2026-08-05 04:18:37 +02:00
RenderCurrentRoute();
2026-07-19 01:13:30 +02:00
window.Render();
window.StartUpdate();
2026-08-05 04:18:37 +02:00
// StartSync rather than StayAlive: /demo drives the ray tracer from the
// animation-frame loop, so the loop has to exist before that route is
// visited. A build of this site without the demo could call StayAlive
// instead and skip the permanent rAF tick entirely.
window.StartSync();
return 0;
}