FBC: NIGHT SHIFT - added a dev resolution, an uncapped perf pass, backface culling and debris batching

This commit is contained in:
dandovlatov 2026-11-24 02:47:33 +04:00
parent a3c8c8ec45
commit 02f94c9695
11 changed files with 252 additions and 39 deletions

View file

@ -38,6 +38,7 @@ add_executable(cntrl
src/render/presenter.cpp src/render/presenter.cpp
src/render/dressing.cpp src/render/dressing.cpp
src/render/debris.cpp src/render/debris.cpp
src/render/box_batch.cpp
src/render/models.cpp src/render/models.cpp
src/render/concrete.cpp src/render/concrete.cpp
src/render/aura.cpp src/render/aura.cpp

View file

@ -51,11 +51,14 @@ cmake --build build -j6
./build/cntrl --seed 42 ./build/cntrl --seed 42
``` ```
The window defaults to 1920×1080; pass `--720p` for the smaller 1280×720 view The window defaults to **1400×900** for everyday development — it fits under a
(`--1080p` restores the default). The scene is shown with its raw palette by 1080p desktop's top bar without being scaled down. `--720p` (1280×720) and
`--1080p` (1920×1080) are explicit test resolutions for perf/visual checks;
`--dev` returns to the default. The scene is shown with its raw palette by
default; pass `--post-fx` for the graded/bloomed/VHS look. default; pass `--post-fx` for the graded/bloomed/VHS look.
Dev tools: `--bot` (kiting autopilot), `--no-damage` (stress mode), Dev tools: `--bot` (kiting autopilot), `--no-damage` (stress mode),
`--uncapped` (drop the 60 FPS target to measure headroom; F10 shows the profiler),
`--screenshot <path> [--screenshot-at <sec>]` for automated visual checks, `--screenshot <path> [--screenshot-at <sec>]` for automated visual checks,
`--hiss-test` (close-up of one buffed Hiss Brute for shader look-dev), `--hiss-test` (close-up of one buffed Hiss Brute for shader look-dev),
`--room-test` (frozen look at the new open-plan room), `--aoe-test` (repeating `--room-test` (frozen look at the new open-plan room), `--aoe-test` (repeating

View file

@ -17,6 +17,18 @@ committed. Continue with **P1** below if more headroom is wanted (e.g. for
| Trilinear concrete filter | — | 60 FPS, GPU 2.6 ms | | Trilinear concrete filter | — | 60 FPS, GPU 2.6 ms |
| Aniso 8x concrete filter (`--aniso 8`) | — | 19 FPS, GPU 40.0 ms (leave off on this GPU) | | Aniso 8x concrete filter (`--aniso 8`) | — | 19 FPS, GPU 40.0 ms (leave off on this GPU) |
**Uncapped headroom (`--uncapped`, removes the 60 FPS target via `SetTargetFPS(0)`):**
| Scenario | FPS | Frame | GPU |
|---|---|---|---|
| 1400x900 dev default, 17 enemies | 337 | 4.0 ms | 1.2 ms |
| 1920x1080 fullscreen, raw | 259 | 3.2 ms | 2.4 ms |
| 1920x1080 fullscreen, `--post-fx` | 172 | 5.6 ms | 2.9 ms |
The overlay title shows `UNCAPPED`; `Present` drops to ~0.3 ms because VSync
waiting is gone, so these numbers show real per-frame cost. Even with the full
bloom chain at 1080p there is ~2.8x headroom over the 60 FPS budget.
CPU section times are tiny: Sim 0.03 ms, Scene ~1.2 ms, UI ~1.5 ms. `Present` CPU section times are tiny: Sim 0.03 ms, Scene ~1.2 ms, UI ~1.5 ms. `Present`
(~14 ms) is `EndDrawing()` waiting for VSync — not a cost to optimize. (~14 ms) is `EndDrawing()` waiting for VSync — not a cost to optimize.
@ -36,15 +48,19 @@ CPU section times are tiny: Sim 0.03 ms, Scene ~1.2 ms, UI ~1.5 ms. `Present`
```sh ```sh
cmake --build build -j6 cmake --build build -j6
# 10 s sample, 17-ish enemies: # 10 s sample at the default dev resolution (1400x900), 17-ish enemies:
timeout 16 ./build/cntrl --seed 42 --bot --no-damage \ timeout 16 ./build/cntrl --seed 42 --bot --no-damage \
--screenshot /tmp/opencode/p1_sample.png --screenshot-at 10 --screenshot /tmp/opencode/p1_sample.png --screenshot-at 10
# true 1080p: add --fullscreen # performance/visual test resolutions: add --720p or --1080p
# true 1080p fullscreen: add --1080p --fullscreen
# late horde: add --screenshot-at 58 and raise timeout to 70 # late horde: add --screenshot-at 58 and raise timeout to 70
# post-FX chain (bloom only runs here): add --post-fx # post-FX chain (bloom only runs here): add --post-fx
# headroom: add --uncapped (removes the 60 FPS target via SetTargetFPS(0))
``` ```
Read the overlay in the PNG (crop top 280x240 and enlarge). The in-game bottom Read the overlay in the PNG (crop top 280x240 and enlarge). The in-game bottom
HUD FPS line is a second sanity check. HUD FPS line is a second sanity check. With `--uncapped` the overlay title shows
`UNCAPPED` and FPS exceeds 60 — that gap is the headroom. GPU time is the number
that matters most: at 60 FPS the frame must stay under 16.6 ms.
## What was done in P0 ## What was done in P0
@ -62,6 +78,16 @@ HUD FPS line is a second sanity check.
(`concrete.cpp:196`) + `Presenter::apply_graphics_settings()` (`concrete.cpp:196`) + `Presenter::apply_graphics_settings()`
(`presenter.cpp:485`) are the runtime hook for the M8 menu. Roadmap M8 records (`presenter.cpp:485`) are the runtime hook for the M8 menu. Roadmap M8 records
the deferred menu UI. the deferred menu UI.
5. **Backface culling on the static mesh.** The winding baked by
`StaticMeshBuilder` is outward-facing, so the two
`rlDisableBackfaceCulling()` calls were unnecessary and shaded both sides of
every baked box. Replaced with `rlEnableBackfaceCulling()` before the draw.
6. **Debris batching.** `src/render/box_batch.{hpp,cpp}` provides `BoxBatch`, a
dynamic mesh that accumulates rotated, tinted unit cubes into **one draw**.
`PaperDebris` (including ink lines and red stamps) and `ConcreteDebris` now
use it instead of one `DrawCube` per shard. Capacity 1024 boxes each, so
debris counts can be raised safely. Verified with `--aoe-test`: 21 debris
items render as 2 draws.
## P1 work (next, in priority order) ## P1 work (next, in priority order)
@ -88,14 +114,33 @@ HUD FPS line is a second sanity check.
last value per uniform (rig/glow/hiss are constant per model type), group draws last value per uniform (rig/glow/hiss are constant per model type), group draws
by model type, or pack per-actor data into one UBO update per frame. by model type, or pack per-actor data into one UBO update per frame.
4. **Optional P2 (only if still short):** `--render-scale 0.75` internal render ## P2 — scalability switches (optional)
target upscaled in the final pass, auto-enabled on iGPUs; draw translucent glow
cylinders with `rlDisableDepthMask()` last. - `--render-scale 0.75` internal render target upscaled in the final pass,
auto-enabled on iGPUs.
- `--quality low|high` preset bundling filter, bloom, render scale and Hiss detail.
- Draw translucent glow cylinders with `rlDisableDepthMask()` last to cut overdraw.
## P3 — deeper batching (partly done)
- **Remaining:** `ScorchDecals::draw` (`debris.cpp`) still issues 5 draws per
decal (2 cylinders + 3 cubes); `CorruptionAura::draw_ground_waves`
(`aura.cpp:108`) is one draw per wave, up to 16. Both can use batch helpers.
- **Done:** paper/concrete debris (BoxBatch), glows/shadows (QuadBatch).
## P4 — assets
- Concrete maps are still 2048x2048 (~7.6 MB raw); 1K with mipmaps would likely
hold the stylized look and help cache behaviour on shared-memory iGPUs.
- Optional distance LOD for enemy meshes.
## Gotchas ## Gotchas
- Window is clamped to monitor height minus 48 unless `--fullscreen`, so default - Default dev window is 1400x900 (fits under the 1080p desktop chrome without
capture is 1834x1032; use `--fullscreen` to test true 1080p. being clamped). The window clamp only bites for `--1080p` on a 1080p monitor —
add `--fullscreen` for a true 1920x1080 capture.
- With the 60 FPS cap on, the `Present` section includes VSync waiting, so its
number is not a cost to optimize. Use `--uncapped` to see real per-frame cost.
- `--post-fx` is opt-in; without it the bloom chain does not run, so P1 bloom - `--post-fx` is opt-in; without it the bloom chain does not run, so P1 bloom
work must be measured with that flag. work must be measured with that flag.
- Keep Trilinear as the default filter. Aniso 8x is a user-facing *option* for - Keep Trilinear as the default filter. Aniso 8x is a user-facing *option* for

View file

@ -23,6 +23,10 @@
namespace { namespace {
constexpr float kFixedDt = 1.0f / 60.0f; constexpr float kFixedDt = 1.0f / 60.0f;
// 1400x900 fits under the monitor chrome on a 1080p display without the
// window clamp scaling it down. 720p/1080p stay as explicit test resolutions.
constexpr int kDevWidth = 1400;
constexpr int kDevHeight = 900;
constexpr int k1080pWidth = 1920; constexpr int k1080pWidth = 1920;
constexpr int k1080pHeight = 1080; constexpr int k1080pHeight = 1080;
constexpr int k720pWidth = 1280; constexpr int k720pWidth = 1280;
@ -30,13 +34,14 @@ constexpr int k720pHeight = 720;
struct Options { struct Options {
std::uint64_t seed = 0xC0FFEEULL; std::uint64_t seed = 0xC0FFEEULL;
int width = k1080pWidth; // 1080p by default; --720p for the old size int width = kDevWidth; // dev default; --720p/--1080p for testing
int height = k1080pHeight; int height = kDevHeight;
const char* screenshot_path = nullptr; // --screenshot <path>: capture the framebuffer const char* screenshot_path = nullptr; // --screenshot <path>: capture the framebuffer
float screenshot_at = 3.0f; // --screenshot-at <sec>: when to capture float screenshot_at = 3.0f; // --screenshot-at <sec>: when to capture
bool bot = false; // --bot: kiting autopilot (M6 balance-bot seed) bool bot = false; // --bot: kiting autopilot (M6 balance-bot seed)
bool no_damage = false; // --no-damage: stress-test mode bool no_damage = false; // --no-damage: stress-test mode
bool post_fx = false; // --post-fx: opt into graded/bloomed look bool post_fx = false; // --post-fx: opt into graded/bloomed look
bool uncapped = false; // --uncapped: remove the 60 FPS target for headroom tests
bool hiss_test = false; // --hiss-test: close-up of one Hiss Brute bool hiss_test = false; // --hiss-test: close-up of one Hiss Brute
bool room_test = false; // --room-test: frozen look at the open-plan room bool room_test = false; // --room-test: frozen look at the open-plan room
bool aoe_test = false; // --aoe-test: repeating area blast for VFX QA bool aoe_test = false; // --aoe-test: repeating area blast for VFX QA
@ -63,6 +68,9 @@ Options parse_options(int argc, char** argv) {
opts.bot = true; opts.bot = true;
} else if (std::strcmp(argv[i], "--no-damage") == 0) { } else if (std::strcmp(argv[i], "--no-damage") == 0) {
opts.no_damage = true; opts.no_damage = true;
} else if (std::strcmp(argv[i], "--dev") == 0) {
opts.width = kDevWidth;
opts.height = kDevHeight;
} else if (std::strcmp(argv[i], "--1080p") == 0) { } else if (std::strcmp(argv[i], "--1080p") == 0) {
opts.width = k1080pWidth; opts.width = k1080pWidth;
opts.height = k1080pHeight; opts.height = k1080pHeight;
@ -71,6 +79,8 @@ Options parse_options(int argc, char** argv) {
opts.height = k720pHeight; opts.height = k720pHeight;
} else if (std::strcmp(argv[i], "--post-fx") == 0) { } else if (std::strcmp(argv[i], "--post-fx") == 0) {
opts.post_fx = true; opts.post_fx = true;
} else if (std::strcmp(argv[i], "--uncapped") == 0) {
opts.uncapped = true;
} else if (std::strcmp(argv[i], "--hiss-test") == 0) { } else if (std::strcmp(argv[i], "--hiss-test") == 0) {
opts.hiss_test = true; opts.hiss_test = true;
} else if (std::strcmp(argv[i], "--room-test") == 0) { } else if (std::strcmp(argv[i], "--room-test") == 0) {
@ -196,8 +206,9 @@ int main(int argc, char** argv) {
char* text = LoadFileText(c); char* text = LoadFileText(c);
if (text != nullptr) { SetGamepadMappings(text); UnloadFileText(text); break; } if (text != nullptr) { SetGamepadMappings(text); UnloadFileText(text); break; }
} }
SetTargetFPS(60); SetTargetFPS(opts.uncapped ? 0 : 60);
PROF_INIT(); PROF_INIT();
PROF_SET_UNCAPPED(opts.uncapped);
ui_font::init(); ui_font::init();
ui_font::init_gui_style(); ui_font::init_gui_style();
clay_ui::init(); clay_ui::init();

90
src/render/box_batch.cpp Normal file
View file

@ -0,0 +1,90 @@
#include "render/box_batch.hpp"
#include "render/profiler.hpp"
#include "raymath.h"
void BoxBatch::init() {
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
verts_per_box_ = cube.vertexCount;
idx_per_box_ = cube.triangleCount * 3;
template_pos_.assign(cube.vertices, cube.vertices + verts_per_box_ * 3);
template_nrm_.assign(cube.normals, cube.normals + verts_per_box_ * 3);
template_idx_.assign(cube.indices, cube.indices + idx_per_box_);
UnloadMesh(cube);
const int verts = kCapacity * verts_per_box_;
pos_.resize(verts * 3);
nrm_.resize(verts * 3);
col_.resize(verts * 4);
idx_.resize(kCapacity * idx_per_box_);
mesh_ = Mesh{};
mesh_.vertexCount = verts;
mesh_.triangleCount = kCapacity * (idx_per_box_ / 3);
mesh_.vertices = pos_.data();
mesh_.normals = nrm_.data();
mesh_.colors = col_.data();
mesh_.indices = idx_.data();
UploadMesh(&mesh_, true);
material_ = LoadMaterialDefault();
ready_ = true;
}
void BoxBatch::shutdown() {
if (!ready_) return;
UnloadMesh(mesh_);
UnloadMaterial(material_);
ready_ = false;
}
void BoxBatch::add(const Vector3& center, const Vector3& size,
float yaw, float pitch, float roll, Color tint) {
if (!ready_ || count_ >= kCapacity) return;
Matrix m = MatrixTranslate(center.x, center.y, center.z);
m = MatrixMultiply(m, MatrixRotateZ(roll * DEG2RAD));
m = MatrixMultiply(m, MatrixRotateX(pitch * DEG2RAD));
m = MatrixMultiply(m, MatrixRotateY(yaw * DEG2RAD));
m = MatrixMultiply(m, MatrixScale(size.x, size.y, size.z));
const int base = count_ * verts_per_box_;
for (int v = 0; v < verts_per_box_; ++v) {
const Vector3 tp{template_pos_[v*3], template_pos_[v*3+1],
template_pos_[v*3+2]};
const Vector3 p = Vector3Transform(tp, m);
const int o = (base + v) * 3;
pos_[o] = p.x; pos_[o+1] = p.y; pos_[o+2] = p.z;
const Vector3 tn{template_nrm_[v*3], template_nrm_[v*3+1],
template_nrm_[v*3+2]};
Vector3 n{
m.m0*tn.x + m.m4*tn.y + m.m8*tn.z,
m.m1*tn.x + m.m5*tn.y + m.m9*tn.z,
m.m2*tn.x + m.m6*tn.y + m.m10*tn.z
};
n = Vector3Normalize(n);
nrm_[o] = n.x; nrm_[o+1] = n.y; nrm_[o+2] = n.z;
const int c = (base + v) * 4;
col_[c] = tint.r; col_[c+1] = tint.g;
col_[c+2] = tint.b; col_[c+3] = tint.a;
}
const int io = count_ * idx_per_box_;
for (int i = 0; i < idx_per_box_; ++i)
idx_[io + i] = static_cast<unsigned short>(base + template_idx_[i]);
++count_;
}
void BoxBatch::draw() {
if (!ready_ || count_ == 0) return;
const int verts = count_ * verts_per_box_;
mesh_.vertexCount = verts;
mesh_.triangleCount = count_ * (idx_per_box_ / 3);
UpdateMeshBuffer(mesh_, 0, pos_.data(), verts * 3 * sizeof(float), 0);
UpdateMeshBuffer(mesh_, 2, nrm_.data(), verts * 3 * sizeof(float), 0);
UpdateMeshBuffer(mesh_, 3, col_.data(), verts * 4, 0);
UpdateMeshBuffer(mesh_, 6, idx_.data(),
count_ * idx_per_box_ * sizeof(unsigned short), 0);
PROF_DRAW_CALL();
DrawMesh(mesh_, material_, MatrixIdentity());
}

33
src/render/box_batch.hpp Normal file
View file

@ -0,0 +1,33 @@
#pragma once
#include <vector>
#include "raylib.h"
// Collects rotated, tinted unit cubes into one dynamic mesh so a burst of
// hundreds of shards costs a single draw call instead of one per cube.
class BoxBatch {
public:
static constexpr int kCapacity = 1024;
void init();
void shutdown();
void begin() { count_ = 0; }
void add(const Vector3& center, const Vector3& size,
float yaw, float pitch, float roll, Color tint);
void draw();
private:
std::vector<float> template_pos_, template_nrm_;
std::vector<unsigned short> template_idx_;
std::vector<float> pos_, nrm_;
std::vector<unsigned char> col_;
std::vector<unsigned short> idx_;
Mesh mesh_{};
Material material_{};
int verts_per_box_ = 0;
int idx_per_box_ = 0;
int count_ = 0;
bool ready_ = false;
};

View file

@ -1,6 +1,7 @@
#include "render/debris.hpp" #include "render/debris.hpp"
#include "render/profiler.hpp" #include "render/profiler.hpp"
#include "raymath.h"
#include "rlgl.h" #include "rlgl.h"
#define DrawCube(...) do { PROF_DRAW_CALL(); DrawCube(__VA_ARGS__); } while(0) #define DrawCube(...) do { PROF_DRAW_CALL(); DrawCube(__VA_ARGS__); } while(0)
@ -23,6 +24,11 @@ float range(float lo, float hi) {
void PaperDebris::init() { void PaperDebris::init() {
shards_.reserve(kCapacity); shards_.reserve(kCapacity);
batch_.init();
}
void PaperDebris::shutdown() {
batch_.shutdown();
} }
void PaperDebris::clear() { void PaperDebris::clear() {
@ -115,6 +121,7 @@ void PaperDebris::draw(Vector3 camera_pos) const {
const Color memo{250, 205, 42, 255}; const Color memo{250, 205, 42, 255};
const Color ink{38, 39, 44, 255}; const Color ink{38, 39, 44, 255};
const Color red{150, 24, 32, 255}; const Color red{150, 24, 32, 255};
batch_.begin();
for (const PaperShard& s : shards_) { for (const PaperShard& s : shards_) {
const float dx = s.pos.x - camera_pos.x; const float dx = s.pos.x - camera_pos.x;
const float dz = s.pos.z - camera_pos.z; const float dz = s.pos.z - camera_pos.z;
@ -123,32 +130,44 @@ void PaperDebris::draw(Vector3 camera_pos) const {
Color tint = s.variant == 2 ? memo : paper; Color tint = s.variant == 2 ? memo : paper;
tint.a = static_cast<unsigned char>(255.0f * std::min(1.0f, fade * 2.2f)); tint.a = static_cast<unsigned char>(255.0f * std::min(1.0f, fade * 2.2f));
rlPushMatrix(); batch_.add(s.pos, {s.size, 0.012f, s.size * 0.74f},
rlTranslatef(s.pos.x, s.pos.y, s.pos.z); s.yaw, s.pitch, s.roll, tint);
rlRotatef(s.roll, 0.0f, 0.0f, 1.0f);
rlRotatef(s.pitch, 1.0f, 0.0f, 0.0f);
rlRotatef(s.yaw, 0.0f, 1.0f, 0.0f);
DrawCube({0.0f, 0.0f, 0.0f}, s.size, 0.012f, s.size * 0.74f, tint);
if (s.variant != 2) { if (s.variant != 2) {
Color ink_tint = ink; Color ink_tint = ink;
ink_tint.a = tint.a; ink_tint.a = tint.a;
DrawCube({0.0f, 0.0f, s.size * 0.10f}, s.size * 0.58f, 0.002f, const Matrix rot = MatrixMultiply(
s.size * 0.055f, ink_tint); MatrixRotateZ(s.roll * DEG2RAD),
MatrixMultiply(MatrixRotateX(s.pitch * DEG2RAD),
MatrixRotateY(s.yaw * DEG2RAD)));
auto offset = [&](Vector3 local) {
const Vector3 o = Vector3Transform(local, rot);
return Vector3{s.pos.x + o.x, s.pos.y + o.y, s.pos.z + o.z};
};
batch_.add(offset({0.0f, 0.0f, s.size * 0.10f}),
{s.size * 0.58f, 0.002f, s.size * 0.055f},
s.yaw, s.pitch, s.roll, ink_tint);
if (s.variant == 1) { if (s.variant == 1) {
DrawCube({-s.size * 0.08f, 0.0f, -s.size * 0.06f}, batch_.add(offset({-s.size * 0.08f, 0.0f, -s.size * 0.06f}),
s.size * 0.42f, 0.002f, s.size * 0.045f, ink_tint); {s.size * 0.42f, 0.002f, s.size * 0.045f},
s.yaw, s.pitch, s.roll, ink_tint);
Color stamp = red; Color stamp = red;
stamp.a = tint.a; stamp.a = tint.a;
DrawCube({s.size * 0.22f, 0.0f, -s.size * 0.20f}, batch_.add(offset({s.size * 0.22f, 0.0f, -s.size * 0.20f}),
s.size * 0.12f, 0.002f, s.size * 0.10f, stamp); {s.size * 0.12f, 0.002f, s.size * 0.10f},
s.yaw, s.pitch, s.roll, stamp);
} }
} }
rlPopMatrix();
} }
batch_.draw();
} }
void ConcreteDebris::init() { void ConcreteDebris::init() {
chunks_.reserve(kCapacity); chunks_.reserve(kCapacity);
batch_.init();
}
void ConcreteDebris::shutdown() {
batch_.shutdown();
} }
void ConcreteDebris::clear() { void ConcreteDebris::clear() {
@ -208,6 +227,7 @@ void ConcreteDebris::update(float dt) {
} }
void ConcreteDebris::draw(Vector3 camera_pos) const { void ConcreteDebris::draw(Vector3 camera_pos) const {
batch_.begin();
for (const ConcreteChunk& c : chunks_) { for (const ConcreteChunk& c : chunks_) {
const float dx = c.pos.x - camera_pos.x; const float dx = c.pos.x - camera_pos.x;
const float dz = c.pos.z - camera_pos.z; const float dz = c.pos.z - camera_pos.z;
@ -215,15 +235,10 @@ void ConcreteDebris::draw(Vector3 camera_pos) const {
const float fade = 1.0f - c.age / c.life; const float fade = 1.0f - c.age / c.life;
Color tint{c.shade, c.shade, static_cast<unsigned char>(c.shade + 4), Color tint{c.shade, c.shade, static_cast<unsigned char>(c.shade + 4),
static_cast<unsigned char>(255.0f * std::min(1.0f, fade * 2.5f))}; static_cast<unsigned char>(255.0f * std::min(1.0f, fade * 2.5f))};
rlPushMatrix(); batch_.add(c.pos, {c.size, c.size * 0.55f, c.size * 0.8f},
rlTranslatef(c.pos.x, c.pos.y, c.pos.z); c.yaw, c.pitch, c.roll, tint);
rlRotatef(c.roll, 0.0f, 0.0f, 1.0f);
rlRotatef(c.pitch, 1.0f, 0.0f, 0.0f);
rlRotatef(c.yaw, 0.0f, 1.0f, 0.0f);
DrawCube({0.0f, 0.0f, 0.0f}, c.size, c.size * 0.55f, c.size * 0.8f,
tint);
rlPopMatrix();
} }
batch_.draw();
} }
void ScorchDecals::add(Vec2 pos, float radius) { void ScorchDecals::add(Vec2 pos, float radius) {

View file

@ -5,6 +5,7 @@
#include "raylib.h" #include "raylib.h"
#include "core/math.hpp" #include "core/math.hpp"
#include "render/box_batch.hpp"
struct PaperShard { struct PaperShard {
Vector3 pos{}; Vector3 pos{};
@ -27,6 +28,7 @@ public:
static constexpr int kCapacity = 320; static constexpr int kCapacity = 320;
void init(); void init();
void shutdown();
void clear(); void clear();
int count() const { return static_cast<int>(shards_.size()); } int count() const { return static_cast<int>(shards_.size()); }
@ -37,6 +39,7 @@ public:
private: private:
std::vector<PaperShard> shards_; std::vector<PaperShard> shards_;
mutable BoxBatch batch_;
}; };
struct ScorchDecal { struct ScorchDecal {
@ -64,6 +67,7 @@ public:
static constexpr int kCapacity = 120; static constexpr int kCapacity = 120;
void init(); void init();
void shutdown();
void clear(); void clear();
int count() const { return static_cast<int>(chunks_.size()); } int count() const { return static_cast<int>(chunks_.size()); }
@ -73,6 +77,7 @@ public:
private: private:
std::vector<ConcreteChunk> chunks_; std::vector<ConcreteChunk> chunks_;
mutable BoxBatch batch_;
}; };
class ScorchDecals { class ScorchDecals {

View file

@ -494,6 +494,8 @@ void Presenter::reset() {
} }
void Presenter::shutdown() { void Presenter::shutdown() {
debris_.shutdown();
concrete_debris_.shutdown();
debris_.clear(); debris_.clear();
concrete_debris_.clear(); concrete_debris_.clear();
scorch_.clear(); scorch_.clear();
@ -608,9 +610,10 @@ void Presenter::draw_office_suite(const Game& game, const ViewCull& cull) {
void Presenter::draw_floor_environment(const Game& game, const ViewCull& cull) { void Presenter::draw_floor_environment(const Game& game, const ViewCull& cull) {
if (static_env_ready_) { if (static_env_ready_) {
rlDisableBackfaceCulling(); // Winding was baked outward in StaticMeshBuilder, so back faces can be
DrawModel(static_env_model_, Vector3{0.0f, 0.0f, 0.0f}, 1.0f, WHITE); // culled like every other mesh instead of shading both sides.
rlEnableBackfaceCulling(); rlEnableBackfaceCulling();
DrawModel(static_env_model_, Vector3{0.0f, 0.0f, 0.0f}, 1.0f, WHITE);
} }
draw_initial_scene(game, cull); draw_initial_scene(game, cull);
@ -878,9 +881,10 @@ void Presenter::draw_environment(const Game& game, const ViewCull& cull) {
// dress it with dark plant blocks and dim spill. A player hugging a wall // dress it with dark plant blocks and dim spill. A player hugging a wall
// then sees more facility instead of an empty unlit void. // then sees more facility instead of an empty unlit void.
if (static_env_ready_) { if (static_env_ready_) {
rlDisableBackfaceCulling(); // Winding was baked outward in StaticMeshBuilder, so back faces can be
DrawModel(static_env_model_, Vector3{0.0f, 0.0f, 0.0f}, 1.0f, WHITE); // culled like every other mesh instead of shading both sides.
rlEnableBackfaceCulling(); rlEnableBackfaceCulling();
DrawModel(static_env_model_, Vector3{0.0f, 0.0f, 0.0f}, 1.0f, WHITE);
} }
// Low partitions, entrance signage and door stripes are baked into the // Low partitions, entrance signage and door stripes are baked into the

View file

@ -124,7 +124,9 @@ void Profiler::draw_overlay() {
const double frame_ms = GetFrameTime() * 1000.0; const double frame_ms = GetFrameTime() * 1000.0;
char buf[128]; char buf[128];
std::snprintf(buf, sizeof(buf), "PROFILE [F10 hide] %s", gpu_ok_ ? "GPU timer ON" : "GPU timer off"); std::snprintf(buf, sizeof(buf), "PROFILE [F10] %s%s",
gpu_ok_ ? "GPU ON" : "GPU off",
uncapped_ ? " UNCAPPED" : "");
DrawText(buf, x + 8, y + 8, 12, Color{245, 197, 24, 240}); DrawText(buf, x + 8, y + 8, 12, Color{245, 197, 24, 240});
std::snprintf(buf, sizeof(buf), "FPS %3d Frame %5.1f ms GPU %5.1f ms", std::snprintf(buf, sizeof(buf), "FPS %3d Frame %5.1f ms GPU %5.1f ms",
GetFPS(), frame_ms, gpu_ms_); GetFPS(), frame_ms, gpu_ms_);

View file

@ -36,6 +36,8 @@ public:
void toggle() { enabled_ = !enabled_; } void toggle() { enabled_ = !enabled_; }
bool enabled() const { return enabled_; } bool enabled() const { return enabled_; }
void set_uncapped(bool on) { uncapped_ = on; }
void set_stats(int enemies, int projectiles, int shards, int debris, int dressing); void set_stats(int enemies, int projectiles, int shards, int debris, int dressing);
void draw_overlay(); void draw_overlay();
@ -48,6 +50,7 @@ private:
Profiler() = default; Profiler() = default;
bool enabled_ = true; bool enabled_ = true;
bool uncapped_ = false;
bool gpu_ok_ = false; bool gpu_ok_ = false;
std::chrono::steady_clock::time_point frame_start_; std::chrono::steady_clock::time_point frame_start_;
@ -80,4 +83,5 @@ private:
#define PROF_DRAW_CALL() profiler::Profiler::instance().count_draw() #define PROF_DRAW_CALL() profiler::Profiler::instance().count_draw()
#define PROF_SET_STATS(e, p, s, d, dr) profiler::Profiler::instance().set_stats(e, p, s, d, dr) #define PROF_SET_STATS(e, p, s, d, dr) profiler::Profiler::instance().set_stats(e, p, s, d, dr)
#define PROF_TOGGLE() profiler::Profiler::instance().toggle() #define PROF_TOGGLE() profiler::Profiler::instance().toggle()
#define PROF_SET_UNCAPPED(on) profiler::Profiler::instance().set_uncapped(on)
#define PROF_DRAW_OVERLAY() profiler::Profiler::instance().draw_overlay() #define PROF_DRAW_OVERLAY() profiler::Profiler::instance().draw_overlay()