Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
226 changes: 120 additions & 106 deletions index.html

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
},
"dependencies": {
"@layoutit/polycss": "^0.2.6",
"nipplejs": "^1.0.4",
"partysocket": "1.1.19"
},
"devDependencies": {
Expand Down
8 changes: 0 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 83 additions & 21 deletions src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ import {
} from "./runtime/multiplayer";
import { createQuakeMenuController } from "./runtime/menu";
import { createQuakeMoversController } from "./runtime/movers";
import { requestQuakeLandscapeOnMobile } from "./runtime/orientation";
import { createQuakeMonsterStateRunner } from "./runtime/quakeMonsterStateRunner";
import {
normalizeQuakeUrlAngle,
Expand Down Expand Up @@ -262,7 +263,6 @@ const {
levelList,
aboutPanel,
optionsPanel,
debugMenuPanel,
disableSoundOption,
disableEnemiesOption,
disableDamageOption,
Expand Down Expand Up @@ -813,7 +813,7 @@ const quakeMultiplayerScoreboard = QUAKE_MULTIPLAYER_ENABLED && quakeHud
? mountQuakeMultiplayerScoreboard(quakeHud)
: null;
let quakeInvertMouse = invertMouseOption?.checked ?? false;
let quakeAlwaysRun = alwaysRunOption?.checked ?? false;
let quakeAlwaysRun = alwaysRunOption?.checked ?? true;
let quakeShowGun = showGunOption?.checked ?? true;
let quakeDynamicLighting = dynamicLightingOption?.checked ?? true;
let quakeImpactParticles = impactParticlesOption?.checked ?? true;
Expand Down Expand Up @@ -1214,7 +1214,6 @@ const scene = createPolyScene(quakeApp, {
textureLighting: "baked",
textureQuality: 1,
textureLeafSizing: "raster",
textureImageRendering: "pixelated",
textureBackend: "atlas",
textureProjection: "affine",
autoCenter: false,
Expand Down Expand Up @@ -1402,19 +1401,17 @@ const menu = createQuakeMenuController({
levelPanel,
aboutPanel,
optionsPanel,
debugPanel: debugMenuPanel,
onSelectNewGame: startQuakeNewGame,
onShowMultiplayer: syncQuakeMultiplayerMenu,
onLoadGame: () => quakeSaveSession.load(),
onSaveGame: () => quakeSaveSession.save(),
onSelectLevel: loadQuakeMap,
onSelectDebug: handleQuakeMenuDebugToggle,
onSelectQuit: quitQuakeToMainMenu,
canLoadGame: () => quakeSaveSession.canLoad(),
canSaveGame: () => quakeSaveSession.canSave(),
isMultiplayerEnabled: () => QUAKE_MULTIPLAYER_MENU_ENABLED,
isQuitEnabled: () => quakeGameplayStarted,
onMenuVisibilityChange: setQuakeDebugShowMenuOption,
onMenuVisibilityChange: handleQuakeMenuVisibilityChange,
onMenuPauseChange: setQuakeMenuPauseState,
onResumeMainMenuFromEscape: suppressQuakeMainMenuOnResumeControlsEnd,
shouldResumeMainMenuOnEscape: shouldResumeQuakeMainMenuOnEscape,
Expand Down Expand Up @@ -2018,6 +2015,7 @@ let currentProgramMetadata: QuakeProgramMetadata | null = null;
let currentCollisionWorld: QuakeCollisionWorld | null = null;
let currentResult: QuakeScene | null = null;
let quakeGameplayStarted = false;
let quakeClickToPlayCenterPrintVisible = false;
let entityByIndex = new Map<number, QuakeEntity>();
let quakeModelPivot = { x: 0, y: 0, z: 0 };
let quakeTransitionSerial = 0;
Expand Down Expand Up @@ -2281,12 +2279,15 @@ quakePlayerLifecycle = createQuakePlayerLifecycleFlow({
let quakeDebugCollisionBypassUntil = 0;
let quakeGamePaused = false;
let quakeGamePausedAt = 0;
let quakeMenuPauseActive = false;
let quakeClickToPlayPauseActive = false;
let quakeMultiplayerInputPaused = QUAKE_MULTIPLAYER_DEBUG_INPUT_PAUSED;

function setQuakeGameplayStarted(started: boolean): void {
quakeGameplayStarted = started;
setQuakeBodyClass("quake-gameplay-started", started);
quakeLoading.handleGameplayStarted(started);
syncQuakeInteractionPresentation();
}

function hidePersistedQuakeLoadingConsole(): void {
Expand Down Expand Up @@ -2322,12 +2323,31 @@ function isQuakeGamePaused(): boolean {
}

function setQuakeMenuPauseState(paused: boolean): void {
quakeMenuPauseActive = paused;
syncQuakePauseState();
}

function setQuakeClickToPlayPauseState(paused: boolean): void {
if (quakeClickToPlayPauseActive === paused) return;
quakeClickToPlayPauseActive = paused;
syncQuakePauseState();
}

function shouldForceQuakeGamePaused(): boolean {
return quakeMenuPauseActive ||
quakeClickToPlayPauseActive ||
menu.isMainMenuOpen() ||
menu.isMenuPanelOpen();
}

function syncQuakePauseState(): void {
const paused = shouldForceQuakeGamePaused();
if (QUAKE_MULTIPLAYER_ENABLED) {
if (QUAKE_MULTIPLAYER_DEBUG_INPUT_PAUSED && !paused) return;
setQuakeMultiplayerInputPaused(paused);
return;
}
setQuakeGamePaused(paused);
applyQuakeGamePaused(paused);
}

function setQuakeMultiplayerInputPaused(paused: boolean): void {
Expand All @@ -2354,6 +2374,10 @@ function setQuakeMultiplayerInputPaused(paused: boolean): void {
}

function setQuakeGamePaused(paused: boolean): void {
applyQuakeGamePaused(paused || shouldForceQuakeGamePaused());
}

function applyQuakeGamePaused(paused: boolean): void {
if (quakeGamePaused === paused) {
syncQuakeInteractionPresentation();
return;
Expand Down Expand Up @@ -2410,6 +2434,15 @@ function toggleQuakeAudioMuted(): void {
setQuakeAudioMuted(!audio.isMuted());
}

function showQuakeShortcutState(label: string, enabled: boolean): void {
quakeTextPresentation.centerPrint(`${label} ${enabled ? "ON" : "OFF"}`);
}

function toggleQuakeAudioMutedShortcut(): void {
toggleQuakeAudioMuted();
showQuakeShortcutState("Sound", !audio.isMuted());
}

function setQuakeEnemiesDisabled(disabled: boolean): void {
quakeEnemiesDisabled = disabled;
shootables.syncMonsterRuntime();
Expand Down Expand Up @@ -2489,24 +2522,46 @@ function setQuakeDebugShowMenuOption(visible: boolean): void {
quakeDebugPanelFlow.setShowMenuOption(visible);
}

function toggleQuakeDebugMode(): void {
quakeDebugPanelFlow.toggleMode();
function handleQuakeMenuVisibilityChange(visible: boolean): void {
setQuakeDebugShowMenuOption(visible);
if (visible && quakeGameplayStarted && document.pointerLockElement === host) {
document.exitPointerLock();
}
syncQuakeInteractionPresentation();
}

function toggleQuakeDebugModeShortcut(): void {
showQuakeShortcutState("Debug", quakeDebugPanelFlow.toggleMode());
}

function toggleQuakeOutlineTextureModeShortcut(): void {
showQuakeShortcutState("Outlines", quakeDebugPanelFlow.toggleOutlineTextureMode());
}

function syncQuakeInteractionPresentation(): void {
const menuSurfaceOpen = menu.isMainMenuOpen() || menu.isMenuPanelOpen();
const debugPointerUnlocked = quakeDebugPanelFlow.isModeEnabled() && document.pointerLockElement !== host;
const pointerUnlocked = document.pointerLockElement !== host;
const gameplayPointerUnlocked = quakeGameplayStarted && pointerUnlocked;
const debugPointerUnlocked = quakeDebugPanelFlow.isModeEnabled() && pointerUnlocked;
const clickToPlayVisible = gameplayPointerUnlocked && !menuSurfaceOpen;
setQuakeClickToPlayPauseState(clickToPlayVisible);
setQuakeBodyClass("quake-debug-active", quakeDebugPanelFlow.isModeEnabled());
setQuakeBodyClass("quake-debug-pointer-unlocked", debugPointerUnlocked);
setQuakeBodyClass("quake-menu-unlocked", menuSurfaceOpen || debugPointerUnlocked);
setQuakeBodyClass("quake-menu-unlocked", menuSurfaceOpen || gameplayPointerUnlocked || debugPointerUnlocked);
syncQuakeClickToPlayCenterPrint(clickToPlayVisible);
}

function handleQuakeMenuDebugToggle(): void {
toggleQuakeDebugMode();
quakeGameplayInput.clearMoveInput();
quakePointerGameplay.clearAttackInput();
quakeGameplayInput.clearCrouchInput();
menu.hideMainMenu();
function syncQuakeClickToPlayCenterPrint(visible: boolean): void {
if (visible) {
if (!quakeClickToPlayCenterPrintVisible) {
quakeTextPresentation.setCenterPrint("CLICK TO PLAY");
quakeClickToPlayCenterPrintVisible = true;
}
return;
}
if (!quakeClickToPlayCenterPrintVisible) return;
quakeTextPresentation.clearCenterPrint();
quakeClickToPlayCenterPrintVisible = false;
}

function handleQuakeDebugDisableAttacksOptionChange(event: Event): void {
Expand Down Expand Up @@ -2601,6 +2656,14 @@ function respawnQuakePlayerFromDeath(): boolean {
}

async function startQuakeNewGame(): Promise<void> {
requestQuakeLandscapeOnMobile(quakeApp).then((result) => {
markQuakeTrace("landscape-lock-request", result);
}).catch((error: unknown) => {
markQuakeTrace("landscape-lock-request", {
reason: "unexpected-error",
message: error instanceof Error ? error.message : String(error),
});
});
await quakePlayerLifecycle.startNewGame();
}

Expand Down Expand Up @@ -4494,9 +4557,9 @@ const quakeInput = createQuakeAppInputController({
shouldPreventGameplayKeyDefault: quakeGameplayInput.shouldPreventGameplayKeyDefault,
showMainMenu: () => menu.showMainMenu(),
syncViewmodelTransform: () => viewmodel.syncTransform(),
toggleAudioMuted: toggleQuakeAudioMuted,
toggleDebugMode: toggleQuakeDebugMode,
toggleOutlineTextureMode: () => quakeDebugPanelFlow.toggleOutlineTextureMode(),
toggleAudioMuted: toggleQuakeAudioMutedShortcut,
toggleDebugMode: toggleQuakeDebugModeShortcut,
toggleOutlineTextureMode: toggleQuakeOutlineTextureModeShortcut,
});

const quakeAppRuntime = createQuakeAppRuntimeContext({
Expand Down Expand Up @@ -4563,7 +4626,6 @@ controls.addEventListener("end", quakeGameplayInput.clearCrouchInput);

syncQuakeHud();
syncQuakeOptionControls();
if (debugMenuPanel) mountQuakeBitmapText(debugMenuPanel);
if (multiplayerPanel) mountQuakeBitmapText(multiplayerPanel);
if (debugPanel) mountQuakeBitmapText(debugPanel);
installQuakeAppDebugHooks();
Expand Down
Binary file added src/assets/main-menu-cursor-baked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/main-menu-help-sprite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/main-menu-level-select-sprite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/main-menu-multiplayer-sprite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/main-menu-options-sprite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/main-menu-plaque-baked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/main-menu-quit-sprite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/main-menu-single-player-sprite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/main-menu-title-baked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/source-port-conback.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 42 additions & 46 deletions src/prepare/assets.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ const quakePrepareReferencedModelsOnly = process.env.QUAKE_PREPARE_REFERENCED_MO
const quakePrepareMapOnlyAllowNewManifest = process.env.QUAKE_PREPARE_MAP_ONLY_ALLOW_NEW_MANIFEST === "1";
const quakeDomTighteningTargets = parseQuakeDomTighteningTargets(process.env.QUAKE_DOM_TIGHTENING ?? "all");
const quakeTriangleAtlasBasis = process.env.QUAKE_TRIANGLE_ATLAS_BASIS === "1";
const quakeDeterministicWorldAtlas = process.env.QUAKE_DETERMINISTIC_WORLD_ATLAS !== "0";
const quakeDeferDeterministicWorldAtlasWrites = process.env.QUAKE_DEFER_DETERMINISTIC_WORLD_ATLAS_WRITES !== "0";
const quakeDeterministicWorldAtlasImagePolicy =
process.env.QUAKE_DETERMINISTIC_WORLD_ATLAS_IMAGE_POLICY?.trim().toLowerCase() ?? "atlas";
Expand Down Expand Up @@ -673,7 +672,7 @@ try {
(mapEntry) => quakeMapPreparePriority(mapEntry, pakEntrySizeByName),
async ([mapPath, outputPath]) => {
const mapName = mapNameFromPakPath(mapPath);
const deterministicRenderBundleMap = quakeDeterministicWorldAtlas && shouldBuildRenderBundleForMap(mapName);
const deterministicRenderBundleMap = shouldBuildRenderBundleForMap(mapName);
return runPrepareStep(`map ${mapName}`, async () => {
const prepared = await runPrepareDetailStep(`map ${mapName} prepared scene`, () =>
createQuakePreparedSceneFromPakBuffer(buffer, {
Expand Down Expand Up @@ -738,57 +737,54 @@ try {
const lightstyleOverlayPolygons = await runPrepareDetailStep(`map ${mapName} lightstyle overlay`, () =>
buildQuakeLightstyleOverlayPolygons(scene.polygons));
const tightenWorldDom = quakeDomTighteningEnabled("world", false);
const tightenWorldAtlasLeaves = tightenWorldDom && !quakeDeterministicWorldAtlas;
prepared.renderBundle = await runPrepareDetailStep(`map ${mapName} render bundle world`, () =>
renderBundleBuilder.build({
mapName,
polygons: scene.polygons,
deferAssetWrites: quakeDeterministicWorldAtlas && quakeDeferDeterministicWorldAtlasWrites,
layoutOnly: quakeDeterministicWorldAtlas,
tightenAtlasLeaves: tightenWorldAtlasLeaves,
deferAssetWrites: quakeDeferDeterministicWorldAtlasWrites,
layoutOnly: true,
tightenAtlasLeaves: false,
optimizeAtlasLeafBasis: tightenWorldDom,
optimizeAtlasLeafHomography: tightenWorldDom,
}));
if (quakeDeterministicWorldAtlas) {
delete prepared.renderBundle.debugOutlineSourceAssetUrls;
delete prepared.renderBundle.debugOutlineAssetUrls;
delete prepared.renderBundle.debugOutlineBackgrounds;
delete prepared.renderBundle.debugOutlineOverpainted;
delete prepared.renderBundle.debugTransparentOutlineSourceAssetUrls;
delete prepared.renderBundle.debugTransparentOutlineAssetUrls;
delete prepared.renderBundle.debugTransparentOutlineBackgrounds;
const deterministicAtlasStats = await runPrepareDetailStep(`map ${mapName} deterministic atlas`, () =>
replaceQuakeRenderBundleWorldAtlas({
imagePolicy: quakeDeterministicWorldAtlasImagePolicy,
mapPath,
name: mapName,
optimizeAtlasLeafBasis: tightenWorldDom,
outputDir: path.join(renderBundleOutputDir, mapName),
pakBuffer: pak,
polygons: scene.polygons,
publicPath: `${quakeRenderBundlePublicPath}/${mapName}`,
readTextureUrl: readGeneratedPublicTextureFile,
renderBundle: prepared.renderBundle,
visibility: prepared.visibility,
}));
prepared.renderBundle.deterministicWorldAtlasStats = deterministicAtlasStats;
assertNoDeferredQuakeRenderBundleAssetReferences(prepared.renderBundle, deterministicAtlasStats);
await runPrepareDetailStep(`map ${mapName} debug outlines`, () =>
addQuakeRenderBundleDebugOutlineAssets(prepared.renderBundle, {
outlineKind: quakeRenderBundleDebugOutlineKindForName(mapName),
outputDir: path.join(renderBundleOutputDir, mapName),
publicPath: `${quakeRenderBundlePublicPath}/${mapName}`,
}));
delete prepared.renderBundle[deterministicAtlasDebugSourceImagesSymbol];
console.log(
`Deterministic world atlas for ${mapName}: ` +
`${deterministicAtlasStats.replacedLeaves} replaced, ` +
`${deterministicAtlasStats.skippedLeaves} skipped, ` +
`${deterministicAtlasStats.pageCount ?? 0} ${deterministicAtlasStats.pageFormat ?? "png"} pages, ` +
`${deterministicAtlasStats.leafImageCount ?? 0} leaf images, ` +
`${formatBytes(deterministicAtlasStats.pageBytes ?? 0)}`,
);
}
delete prepared.renderBundle.debugOutlineSourceAssetUrls;
delete prepared.renderBundle.debugOutlineAssetUrls;
delete prepared.renderBundle.debugOutlineBackgrounds;
delete prepared.renderBundle.debugOutlineOverpainted;
delete prepared.renderBundle.debugTransparentOutlineSourceAssetUrls;
delete prepared.renderBundle.debugTransparentOutlineAssetUrls;
delete prepared.renderBundle.debugTransparentOutlineBackgrounds;
const deterministicAtlasStats = await runPrepareDetailStep(`map ${mapName} deterministic atlas`, () =>
replaceQuakeRenderBundleWorldAtlas({
imagePolicy: quakeDeterministicWorldAtlasImagePolicy,
mapPath,
name: mapName,
optimizeAtlasLeafBasis: tightenWorldDom,
outputDir: path.join(renderBundleOutputDir, mapName),
pakBuffer: pak,
polygons: scene.polygons,
publicPath: `${quakeRenderBundlePublicPath}/${mapName}`,
readTextureUrl: readGeneratedPublicTextureFile,
renderBundle: prepared.renderBundle,
visibility: prepared.visibility,
}));
prepared.renderBundle.deterministicWorldAtlasStats = deterministicAtlasStats;
assertNoDeferredQuakeRenderBundleAssetReferences(prepared.renderBundle, deterministicAtlasStats);
await runPrepareDetailStep(`map ${mapName} debug outlines`, () =>
addQuakeRenderBundleDebugOutlineAssets(prepared.renderBundle, {
outlineKind: quakeRenderBundleDebugOutlineKindForName(mapName),
outputDir: path.join(renderBundleOutputDir, mapName),
publicPath: `${quakeRenderBundlePublicPath}/${mapName}`,
}));
delete prepared.renderBundle[deterministicAtlasDebugSourceImagesSymbol];
console.log(
`Deterministic world atlas for ${mapName}: ` +
`${deterministicAtlasStats.replacedLeaves} replaced, ` +
`${deterministicAtlasStats.skippedLeaves} skipped, ` +
`${deterministicAtlasStats.pageCount ?? 0} ${deterministicAtlasStats.pageFormat ?? "png"} pages, ` +
`${deterministicAtlasStats.leafImageCount ?? 0} leaf images, ` +
`${formatBytes(deterministicAtlasStats.pageBytes ?? 0)}`,
);
if (lightstyleOverlayPolygons.length) {
prepared.lightstyleRenderBundle = await runPrepareDetailStep(`map ${mapName} render bundle lightstyle`, () =>
renderBundleBuilder.build({
Expand Down
2 changes: 2 additions & 0 deletions src/prepare/bundle.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2497,6 +2497,7 @@ function directTightenedAtlasLeafExtraStyle(rawStyle) {
part.name !== "background-position" &&
part.name !== "background-size" &&
part.name !== "background-repeat" &&
part.name !== "image-rendering" &&
part.name !== "width" &&
part.name !== "height"
)
Expand Down Expand Up @@ -3102,6 +3103,7 @@ function stripRenderBundleOutputStyleMetadata(style) {
return renderBundleStyleDeclarations(style)
.filter((part) =>
part.name !== "background-repeat" &&
part.name !== "image-rendering" &&
!part.name.startsWith("--pn") &&
!part.name.startsWith("--polycss-atlas-")
)
Expand Down
Loading
Loading