Skip to content

Commit fe11e10

Browse files
committed
Merge branch 'worktree-agent-a50e2e8d'
2 parents a54d8a8 + 21092dd commit fe11e10

10 files changed

Lines changed: 49 additions & 71 deletions

File tree

demos/audio-showcase/audio-showcase.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
*/
1515

1616
import {
17-
getViewportSize,
1817
drawText,
1918
isKeyPressed,
2019
isKeyDown,
@@ -134,9 +133,7 @@ function updateScene1(dt: number) {
134133
updateSpatialAudio();
135134
}
136135

137-
function drawScene1() {
138-
const vp = getViewportSize();
139-
136+
function drawScene1(vpH: number) {
140137
// Draw sound sources
141138
for (const source of soundSources) {
142139
drawSprite({ textureId: source.color, x: source.x, y: source.y, w: 32, h: 32 });
@@ -158,7 +155,7 @@ function drawScene1() {
158155
hud.text("Click: Place sound source", 10, 50, { scale: 1 });
159156
hud.text(`Listener: (${Math.floor(listenerPos.x)}, ${Math.floor(listenerPos.y)})`, 10, 70, { scale: 1 });
160157
hud.text(`Sources: ${soundSources.length}`, 10, 90, { scale: 1 });
161-
hud.text("Press 2 or 3 to switch scenes", 10, vp.height - 20, { scale: 1 });
158+
hud.text("Press 2 or 3 to switch scenes", 10, vpH - 20, { scale: 1 });
162159
}
163160

164161
//=============================================================================
@@ -243,9 +240,7 @@ function updateScene2(dt: number) {
243240
}
244241
}
245242

246-
function drawScene2() {
247-
const vp = getViewportSize();
248-
243+
function drawScene2(vpH: number) {
249244
// Draw zones
250245
for (const zone of zones) {
251246
drawSprite({
@@ -289,7 +284,7 @@ function drawScene2() {
289284
opacity: 0.8,
290285
});
291286

292-
hud.text("Press 1 or 3 to switch scenes", 10, vp.height - 20, { scale: 1 });
287+
hud.text("Press 1 or 3 to switch scenes", 10, vpH - 20, { scale: 1 });
293288
}
294289

295290
//=============================================================================
@@ -354,9 +349,7 @@ function updateScene3() {
354349
}
355350
}
356351

357-
function drawScene3() {
358-
const vp = getViewportSize();
359-
352+
function drawScene3(vpH: number) {
360353
// HUD
361354
hud.text("Scene 3: Mixer Panel", 10, 10, { scale: 2 });
362355
hud.text("Adjust bus volumes and test sounds", 10, 30, { scale: 1 });
@@ -381,7 +374,7 @@ function drawScene3() {
381374
drawButton(testAmbientButton);
382375
drawButton(testVoiceButton);
383376

384-
hud.text("Press 1 or 2 to switch scenes", 10, vp.height - 20, { scale: 1 });
377+
hud.text("Press 1 or 2 to switch scenes", 10, vpH - 20, { scale: 1 });
385378
}
386379

387380
//=============================================================================
@@ -395,6 +388,7 @@ const game = createGame({ background: { r: 30 / 255, g: 30 / 255, b: 40 / 255 }
395388

396389
game.onFrame((ctx) => {
397390
const dt = ctx.dt;
391+
const { vpH } = ctx;
398392

399393
// Scene switching
400394
if (isKeyPressed("1") && currentScene !== 1) {
@@ -414,12 +408,12 @@ game.onFrame((ctx) => {
414408
// Update current scene
415409
if (currentScene === 1) {
416410
updateScene1(dt);
417-
drawScene1();
411+
drawScene1(vpH);
418412
} else if (currentScene === 2) {
419413
updateScene2(dt);
420-
drawScene2();
414+
drawScene2(vpH);
421415
} else if (currentScene === 3) {
422416
updateScene3();
423-
drawScene3();
417+
drawScene3(vpH);
424418
}
425419
});

demos/gamepad-platformer/gamepad-platformer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import {
1313
drawSprite,
1414
createSolidTexture,
15-
getViewportSize,
1615
drawText,
1716
getDefaultFont,
1817
isKeyPressed,

demos/hex-strategy/hex-strategy.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
getCamera,
1717
isKeyPressed,
1818
createSolidTexture,
19-
getViewportSize,
2019
drawText,
2120
followTargetSmooth,
2221
getMouseWorldPosition,
@@ -405,7 +404,6 @@ function drawHoverHighlight(): void {
405404

406405
function drawHUD(): void {
407406
const cam = getCamera();
408-
const vp = getViewportSize();
409407
const scale = 1 / cam.zoom;
410408
const hudX = cam.x;
411409
const hudY = cam.y;

demos/isometric-dungeon/isometric-dungeon.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
getCamera,
1818
isKeyPressed,
1919
createSolidTexture,
20-
getViewportSize,
2120
drawText,
2221
setCameraBounds,
2322
trackTarget,
@@ -610,7 +609,6 @@ function render(): void {
610609

611610
// 6. HUD
612611
const cam = getCamera();
613-
const vp = getViewportSize();
614612
const scale = 1 / cam.zoom;
615613
const hudX = cam.x;
616614
const hudY = cam.y;

demos/lighting-showcase/lighting-showcase.ts

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
isKeyDown,
2727
isKeyPressed,
2828
createSolidTexture,
29-
getViewportSize,
3029
drawText,
3130
setAmbientLight,
3231
addPointLight,
@@ -81,8 +80,7 @@ setGIQuality({ probeSpacing: 4, cascadeCount: 5 });
8180

8281
// --- Scene builders ---
8382

84-
function drawDungeonScene(dt: number) {
85-
const { width: VPW, height: VPH } = getViewportSize();
83+
function drawDungeonScene(dt: number, VPW: number, VPH: number) {
8684
setBackgroundColor({ r: 0.02, g: 0.02, b: 0.05 });
8785
setAmbientLight(0.05, 0.05, 0.08);
8886

@@ -155,8 +153,7 @@ function drawDungeonScene(dt: number) {
155153
addPointLight(VPW - 72, 408, 120, torchColor[0], torchColor[1], torchColor[2], flicker * 0.5);
156154
}
157155

158-
function drawLavaScene(dt: number) {
159-
const { width: VPW, height: VPH } = getViewportSize();
156+
function drawLavaScene(dt: number, VPW: number, VPH: number) {
160157
setBackgroundColor({ r: 0.05, g: 0.01, b: 0.0 });
161158
setAmbientLight(0.08, 0.03, 0.02);
162159

@@ -197,8 +194,7 @@ function drawLavaScene(dt: number) {
197194
}
198195
}
199196

200-
function drawOutdoorScene(dt: number) {
201-
const { width: VPW, height: VPH } = getViewportSize();
197+
function drawOutdoorScene(dt: number, VPW: number, VPH: number) {
202198

203199
// Use day/night cycle
204200
setDayNightCycle({ timeOfDay });
@@ -257,8 +253,7 @@ function drawOutdoorScene(dt: number) {
257253
}
258254
}
259255

260-
function drawNeonScene(dt: number) {
261-
const { width: VPW, height: VPH } = getViewportSize();
256+
function drawNeonScene(dt: number, VPW: number, VPH: number) {
262257
setBackgroundColor({ r: 0.02, g: 0.02, b: 0.04 });
263258
setAmbientLight(0.03, 0.03, 0.05);
264259

@@ -303,8 +298,7 @@ function drawNeonScene(dt: number) {
303298
}
304299
}
305300

306-
function drawComparisonScene(dt: number) {
307-
const { width: VPW, height: VPH } = getViewportSize();
301+
function drawComparisonScene(dt: number, VPW: number, VPH: number) {
308302
setBackgroundColor({ r: 0.02, g: 0.02, b: 0.05 });
309303
setAmbientLight(0.05, 0.05, 0.08);
310304

@@ -375,7 +369,7 @@ game.onFrame((ctx) => {
375369
const dt = ctx.dt;
376370
frameCount++;
377371

378-
const { width: VPW, height: VPH } = getViewportSize();
372+
const { vpW: VPW, vpH: VPH } = ctx;
379373

380374
clearLights();
381375
clearEmissives();
@@ -414,7 +408,6 @@ game.onFrame((ctx) => {
414408

415409
// Player movement with collision
416410
const speed = 200 * dt;
417-
const { width: VPW2, height: VPH2 } = getViewportSize();
418411
let newX = playerX;
419412
let newY = playerY;
420413
if (isKeyDown("ArrowLeft")) newX -= speed;
@@ -427,14 +420,14 @@ game.onFrame((ctx) => {
427420
// Wall thickness on each side
428421
const wallW = 64;
429422
// Pillar bounds (scene 1 only)
430-
const pillarL = VPW2 / 2 - 32;
431-
const pillarR = VPW2 / 2 + 32;
432-
const pillarT = VPH2 / 2 - 64;
423+
const pillarL = VPW / 2 - 32;
424+
const pillarR = VPW / 2 + 32;
425+
const pillarT = VPH / 2 - 64;
433426
const pillarB = pillarT + 128;
434427

435428
// Clamp to walls
436-
newX = Math.max(wallW + ph, Math.min(VPW2 - wallW - ph, newX));
437-
newY = Math.max(ph, Math.min(VPH2 - ph, newY));
429+
newX = Math.max(wallW + ph, Math.min(VPW - wallW - ph, newX));
430+
newY = Math.max(ph, Math.min(VPH - ph, newY));
438431

439432
// Pillar collision (dungeon scene)
440433
if (currentScene === 1) {
@@ -459,19 +452,19 @@ game.onFrame((ctx) => {
459452
// Draw current scene
460453
switch (currentScene) {
461454
case 1:
462-
drawDungeonScene(dt);
455+
drawDungeonScene(dt, VPW, VPH);
463456
break;
464457
case 2:
465-
drawLavaScene(dt);
458+
drawLavaScene(dt, VPW, VPH);
466459
break;
467460
case 3:
468-
drawOutdoorScene(dt);
461+
drawOutdoorScene(dt, VPW, VPH);
469462
break;
470463
case 4:
471-
drawNeonScene(dt);
464+
drawNeonScene(dt, VPW, VPH);
472465
break;
473466
case 5:
474-
drawComparisonScene(dt);
467+
drawComparisonScene(dt, VPW, VPH);
475468
break;
476469
}
477470

demos/msdf-text-showcase/msdf-text-showcase.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import {
55
isKeyPressed,
6-
getViewportSize,
76
drawText,
87
getDefaultFont,
98
getDefaultMSDFFont,
@@ -53,24 +52,22 @@ function drawTitle(title: string) {
5352
});
5453
}
5554

56-
function drawHelpBar() {
57-
const { height } = getViewportSize();
55+
function drawHelpBar(vpH: number) {
5856
drawText(
5957
`[1-7] Switch section Current: ${currentSection}/${totalSections}`,
6058
20,
61-
height - 24,
59+
vpH - 24,
6260
{ font: getDefaultFont(), scale: 2, tint: gray, screenSpace: true, layer: 200 },
6361
);
6462
}
6563

6664
// --- Section Renderers ---
6765

68-
function drawSection1_Comparison() {
66+
function drawSection1_Comparison(vpW: number) {
6967
drawTitle("1: Bitmap vs MSDF Comparison");
7068

7169
const bitmap = getDefaultFont();
7270
const msdf = getDefaultMSDFFont();
73-
const { width: vpW } = getViewportSize();
7471
const halfW = vpW / 2;
7572

7673
// Column headers
@@ -595,6 +592,8 @@ const game = createGame({ name: "msdf-text-showcase", background: { r: 38 / 255,
595592
// --- Main Frame Loop ---
596593

597594
game.onFrame((ctx) => {
595+
const { vpW, vpH } = ctx;
596+
598597
// Section switching with number keys
599598
if (isKeyPressed("1")) currentSection = 1;
600599
if (isKeyPressed("2")) currentSection = 2;
@@ -607,7 +606,7 @@ game.onFrame((ctx) => {
607606
// Draw active section
608607
switch (currentSection) {
609608
case 1:
610-
drawSection1_Comparison();
609+
drawSection1_Comparison(vpW);
611610
break;
612611
case 2:
613612
drawSection2_Outlines();
@@ -630,7 +629,7 @@ game.onFrame((ctx) => {
630629
}
631630

632631
// Always draw the help bar
633-
drawHelpBar();
632+
drawHelpBar(vpH);
634633
});
635634

636635
// --- Agent Registration ---

demos/parallax-scroller/parallax-scroller.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
isKeyDown,
2626
isKeyPressed,
2727
createSolidTexture,
28-
getViewportSize,
2928
drawText,
3029
setCameraBounds,
3130
getCameraBounds,
@@ -230,8 +229,7 @@ function updateCamera(): void {
230229
}
231230

232231
// --- Rendering ---
233-
function render(): void {
234-
const vp = getViewportSize();
232+
function render(vpW: number, vpH: number): void {
235233
const cam = getCamera();
236234

237235
// Layer 0: Far sky (fixed)
@@ -376,8 +374,8 @@ function render(): void {
376374
const dz = getCameraDeadzone();
377375
if (dz) {
378376
// Viewport center in world space = cam.x + vpW/(2*zoom)
379-
const centerX = cam.x + (vp.width / 2) / cam.zoom;
380-
const centerY = cam.y + (vp.height / 2) / cam.zoom;
377+
const centerX = cam.x + (vpW / 2) / cam.zoom;
378+
const centerY = cam.y + (vpH / 2) / cam.zoom;
381379
const dzX = centerX - dz.width / 2;
382380
const dzY = centerY - dz.height / 2;
383381
drawSprite({
@@ -398,11 +396,12 @@ const app = createGame({ name: "parallax-scroller" });
398396

399397
// --- Frame loop ---
400398
app.onFrame((ctx) => {
399+
const { vpW, vpH } = ctx;
401400
updateTweens(ctx.dt);
402401
handleInput();
403402
updatePlayer(ctx.dt);
404403
updateCamera();
405-
render();
404+
render(vpW, vpH);
406405
});
407406

408407
// --- Agent state ---

demos/roguelike/roguelike-visual.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createRoguelikeGame, movePlayer } from "./roguelike.ts";
22
import type { Direction, RoguelikeState } from "./roguelike.ts";
33
import { WALL, FLOOR, CORRIDOR, STAIRS_DOWN } from "./dungeon.ts";
44
import {
5-
setCamera, isKeyPressed, getViewportSize,
5+
setCamera, isKeyPressed,
66
setAmbientLight, addPointLight, clearLights,
77
drawSprite,
88
} from "../../runtime/rendering/index.ts";
@@ -63,7 +63,9 @@ const KEY_MAP: Record<string, Direction> = {
6363
Space: "wait",
6464
};
6565

66-
game.onFrame(() => {
66+
game.onFrame((ctx) => {
67+
const { vpW, vpH } = ctx;
68+
6769
// Handle input
6870
for (const [key, dir] of Object.entries(KEY_MAP)) {
6971
if (isKeyPressed(key)) {
@@ -73,13 +75,12 @@ game.onFrame(() => {
7375
}
7476

7577
// Camera follows player (center player in viewport)
76-
const rlVp = getViewportSize();
7778
const zoom = 2;
7879
const playerWorldX = state.player.pos.x * TILE_SIZE + TILE_SIZE / 2;
7980
const playerWorldY = state.player.pos.y * TILE_SIZE + TILE_SIZE / 2;
8081
setCamera(
81-
playerWorldX - rlVp.width / (2 * zoom),
82-
playerWorldY - rlVp.height / (2 * zoom),
82+
playerWorldX - vpW / (2 * zoom),
83+
playerWorldY - vpH / (2 * zoom),
8384
zoom,
8485
);
8586

0 commit comments

Comments
 (0)