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
65 changes: 61 additions & 4 deletions src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,40 @@ const quakeEntityMeshes = createQuakeEntityMeshMountFlow({
sceneElement,
schedulePresentationResync: (handle) => world.schedulePresentationResync(handle),
});

function quakeShootablePrewarmLeavesAt(origin: [number, number, number]): Set<number> | null {
const visibility = currentResult?.visibility;
const visibleLeaves = visibility?.visibleLeavesAt(origin) ?? null;
const metadata = visibility?.metadata;
if (!visibility || !metadata || !visibleLeaves) return visibleLeaves;
const leafIndex = visibility.leafIndexAt(origin);
const leaf = metadata.leaves[leafIndex];
if (!leaf) return visibleLeaves;
const prewarmLeaves = new Set(visibleLeaves);
for (const adjacentLeafIndex of leaf.adjacentLeafIndexes) {
const adjacentLeaf = metadata.leaves[adjacentLeafIndex];
if (!adjacentLeaf) continue;
prewarmLeaves.add(adjacentLeafIndex);
for (const visibleLeafIndex of adjacentLeaf.visibleLeafIndexes ?? []) {
prewarmLeaves.add(visibleLeafIndex);
}
}
for (const mover of movers.debugStats().movers) {
if (mover.kind === "button" || mover.mode === "closed") continue;
const modelIndex = entityByIndex.get(mover.entityIndex)?.modelIndex;
if (modelIndex === undefined) continue;
for (const moverLeaf of world.modelLeaves(modelIndex)) {
const leaf = metadata.leaves[moverLeaf.leafIndex];
if (!leaf) continue;
prewarmLeaves.add(moverLeaf.leafIndex);
for (const visibleLeafIndex of leaf.visibleLeafIndexes ?? []) {
prewarmLeaves.add(visibleLeafIndex);
}
}
}
return prewarmLeaves;
}

const menu = createQuakeMenuController({
enabled: QUAKE_MENU_ENABLED,
host,
Expand Down Expand Up @@ -1750,11 +1784,19 @@ const shootables = createQuakeShootablesController({
onDestroyed: (entity) => {
if (entity.classname.startsWith("monster_")) quakeLevelStats.markMonsterKilled(entity.index);
},
onExplosion: (event) => {
quakeImpactParticleFlow.spawnExplosion({
flavor: event.flavor,
origin: event.origin,
radiusUnits: event.radiusUnits,
});
},
pointToPoly: quakeCameraView.pointToPoly,
shouldSpawn: shouldSpawnQuakeShootableForCurrentMode,
pixelate: world.pixelate,
schedulePresentationResync: world.schedulePresentationResync,
visibleLeavesAt: world.visibleLeavesAt,
prewarmLeavesAt: quakeShootablePrewarmLeavesAt,
fireTarget: fireQuakeTarget,
playSound: (soundPath, options) => audio.playSound(soundPath, options),
});
Expand Down Expand Up @@ -1883,6 +1925,13 @@ const weapons = createQuakeWeaponsController({
origin: event.origin,
});
},
onExplosionImpact: (event) => {
quakeImpactParticleFlow.spawnExplosion({
flavor: event.flavor,
origin: event.origin,
radiusUnits: event.radiusUnits,
});
},
onHit: () => quakeWeaponPresentation.flashCrosshairHit(),
onWallImpact: (event) => {
quakeImpactParticleFlow.spawnWallImpact({
Expand Down Expand Up @@ -2087,6 +2136,7 @@ quakeMoverInteractions = createQuakeMoverInteractionFlow({
),
shootables,
showCenterPrint: (text) => quakeTextPresentation.centerPrint(text),
syncShootablesVisibility: (origin, force) => shootables.syncVisibility(origin, force),
syncCrosshairTarget: syncQuakeCrosshairTarget,
});
const quakeAssetWarmup = createQuakeAssetWarmupFlow({
Expand Down Expand Up @@ -2509,13 +2559,15 @@ function createNoopQuakeImpactParticleFlow(): QuakeImpactParticleFlow {
dispose: () => undefined,
setEnabled: () => undefined,
spawnBlood: () => undefined,
spawnExplosion: () => undefined,
spawnWallImpact: () => undefined,
};
}

function quakeWallImpactParticleCount(effect: QuakeWeaponWallImpactEffect): number {
if (effect === "spike") return 2;
return 3;
if (effect === "spike") return 4;
if (effect === "superspike") return 6;
return 5;
}

function setQuakeDebugShowMenuOption(visible: boolean): void {
Expand Down Expand Up @@ -4406,6 +4458,11 @@ function syncPlayerCollision(): void {
getPlayer().syncCollision();
}

function handleQuakeControlsChange(): void {
syncPlayerCollision();
shootables.syncVisibility(controls.getOrigin());
}

function disposeQuakeApp(): void {
quakeAppDisposed = true;
stopQuakeMultiplayerScene("app-dispose");
Expand Down Expand Up @@ -4440,7 +4497,7 @@ function disposeQuakeApp(): void {
debugShowLabelsOption?.removeEventListener("change", quakeDebugPanelFlow.handleShowLabelsOptionChange);
quakeDebugRecorder.dispose();
quakeDebugPanelFlow.stopStats();
controls.removeEventListener("change", syncPlayerCollision);
controls.removeEventListener("change", handleQuakeControlsChange);
controls.removeEventListener("end", quakeGameplayInput.clearCrouchInput);
controls.destroy();
menu.dispose();
Expand Down Expand Up @@ -4621,7 +4678,7 @@ debugShowTexturesOption?.addEventListener("change", quakeDebugPanelFlow.handleSh
debugFlyModeOption?.addEventListener("change", handleQuakeDebugFlyModeOptionChange);
debugShowOutlinesOption?.addEventListener("change", quakeDebugPanelFlow.handleShowOutlinesOptionChange);
debugShowLabelsOption?.addEventListener("change", quakeDebugPanelFlow.handleShowLabelsOptionChange);
controls.addEventListener("change", syncPlayerCollision);
controls.addEventListener("change", handleQuakeControlsChange);
controls.addEventListener("end", quakeGameplayInput.clearCrouchInput);

syncQuakeHud();
Expand Down
53 changes: 44 additions & 9 deletions src/prepare/assets.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3381,9 +3381,12 @@ async function writeQuakeWeaponModelFiles(assets, sourceProgramFacts, renderBund
}

function buildQuakeWeaponModels(assets, sourceProgramFacts, renderBundleBuilder) {
const muzzleFlashModelPaths = quakePlayerWeaponMuzzleFlashViewModelPaths(sourceProgramFacts);
return Promise.all(
quakePlayerWeaponViewModelPaths(sourceProgramFacts)
.map((modelPath) => buildQuakeWeaponModel(assets, renderBundleBuilder, modelPath)),
.map((modelPath) => buildQuakeWeaponModel(assets, renderBundleBuilder, modelPath, {
muzzleFlash: muzzleFlashModelPaths.has(modelPath),
})),
);
}

Expand All @@ -3406,6 +3409,30 @@ function quakePlayerWeaponViewModelPaths(sourceProgramFacts) {
return paths;
}

function quakePlayerWeaponMuzzleFlashViewModelPaths(sourceProgramFacts) {
const paths = new Set();
const profiles = sourceProgramFacts?.playerWeapons?.profiles;
if (!profiles || typeof profiles !== "object") return paths;
for (const profile of Object.values(profiles)) {
const modelPath = quakeNormalizedWeaponViewModelPath(profile?.presentation?.viewModelPath);
if (!modelPath || !quakeWeaponPresentationHasMuzzleFlash(profile?.presentation)) continue;
paths.add(modelPath);
}
return paths;
}

function quakeWeaponPresentationHasMuzzleFlash(presentation) {
const variants = presentation?.fireAnimation?.variants;
return Array.isArray(variants) && variants.some((variant) =>
Array.isArray(variant?.frames) && variant.frames.some((frame) => frame?.muzzleFlash === true),
);
}

function quakeNormalizedWeaponViewModelPath(value) {
const modelPath = typeof value === "string" ? value.trim().toLowerCase() : "";
return /^progs\/v_[a-z0-9_]+\.mdl$/.test(modelPath) ? modelPath : "";
}

function quakePlayerWeaponProjectileModelPaths(sourceProgramFacts) {
const paths = [];
const seen = new Set();
Expand Down Expand Up @@ -3442,7 +3469,12 @@ function quakeWeaponModelUrlMap(sourceProgramFacts) {
return urls;
}

async function buildQuakeWeaponModel(assets, renderBundleBuilder, modelPath = QUAKE_DEFAULT_WEAPON_VIEWMODEL_PATH) {
async function buildQuakeWeaponModel(
assets,
renderBundleBuilder,
modelPath = QUAKE_DEFAULT_WEAPON_VIEWMODEL_PATH,
options = {},
) {
const model = parseQuakeAliasModel(assets, modelPath);
const idleFrame = model.frames[0];
const fireFrame = model.frames[1] ?? idleFrame;
Expand All @@ -3456,10 +3488,13 @@ async function buildQuakeWeaponModel(assets, renderBundleBuilder, modelPath = QU
brightness: textureBrightness,
});
const polygons = model.triangles.map((triangle) => {
const uvs = triangle.indices.map((index) => quakeAliasUv(model, triangle, index));
const isNozzle = isQuakeWeaponNozzlePolygon(uvs);
const indices = quakeAliasRenderBundleWindingOrder(triangle.indices);
const uvs = quakeAliasRenderBundleWindingOrder(
triangle.indices.map((index) => quakeAliasUv(model, triangle, index)),
);
const isNozzle = options.muzzleFlash === true && isQuakeWeaponNozzlePolygon(uvs);
const frame = isNozzle ? fireFrame : idleFrame;
const vertices = triangle.indices.map((index) => quakeWeaponVertex(frame.vertices[index]));
const vertices = indices.map((index) => quakeWeaponVertex(frame.vertices[index]));
if (isNozzle) {
return {
vertices,
Expand All @@ -3476,16 +3511,16 @@ async function buildQuakeWeaponModel(assets, renderBundleBuilder, modelPath = QU
uvs,
};
});
const tightenWeaponDom = quakeDomTighteningEnabled("other", false);
return {
source: modelPath,
renderBundle: await renderBundleBuilder.build({
bundleName: quakeWeaponRenderBundleName(modelPath),
polygons: anchorQuakeWeaponPolygons(polygons),
extractLeafStyles: true,
tightenAtlasLeaves: tightenWeaponDom,
optimizeAtlasLeafBasis: tightenWeaponDom,
optimizeAtlasLeafHomography: tightenWeaponDom,
// Viewmodel leaves are close to camera; atlas tightening can detach visible weapon faces.
tightenAtlasLeaves: false,
optimizeAtlasLeafBasis: false,
optimizeAtlasLeafHomography: false,
}),
};
}
Expand Down
49 changes: 37 additions & 12 deletions src/quake.css
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,34 @@ body.quake-menu-open #quake-hud {
.quake-impact-particle-dust-a,
.quake-impact-particle-dust-b,
.quake-impact-particle-dust-c {
border-radius: 1px;
border-radius: 0;
}
.quake-impact-particle-dust-a {
background: #444444;
background: #c8c8c8;
}
.quake-impact-particle-dust-b {
background: #444444;
background: #808080;
}
.quake-impact-particle-dust-c {
background: #444444;
background: #202020;
}
.quake-impact-particle-explosion-a,
.quake-impact-particle-explosion-b,
.quake-impact-particle-explosion-c,
.quake-impact-particle-explosion-d {
border-radius: 50%;
}
.quake-impact-particle-explosion-a {
background: #ffe06a;
}
.quake-impact-particle-explosion-b {
background: #f06416;
}
.quake-impact-particle-explosion-c {
background: #6b625a;
}
.quake-impact-particle-explosion-d {
background: #29231f;
}
body.quake-loading #quake-damage-overlay,
body.quake-loading #quake-bonus-overlay,
Expand Down Expand Up @@ -2263,7 +2281,8 @@ body.quake-debug-outlines #quake-debug-outline-legend {
visibility: visible;
}
.polycss-mesh.shootable.quake-shootable-prewarmed {
visibility: hidden;
visibility: visible;
opacity: 0.001;
pointer-events: none;
transition: none;
}
Expand Down Expand Up @@ -2337,11 +2356,16 @@ body.quake-menu-unlocked #quake-weapon {
}
#quake-mobile-move-zone .joystick {
position: absolute;
left: 72px;
top: 72px;
left: 50%;
top: 50%;
width: 108px;
height: 108px;
margin-left: -54px;
margin-top: -54px;
display: block;
z-index: 999;
opacity: 0.58;
pointer-events: none;
touch-action: none;
user-select: none;
transition: opacity 80ms linear;
Expand All @@ -2350,20 +2374,21 @@ body.quake-menu-unlocked #quake-weapon {
#quake-mobile-move-zone .joystick .front {
position: absolute;
display: block;
left: 0;
top: 0;
pointer-events: none;
border-radius: 50%;
}
#quake-mobile-move-zone .joystick .back {
left: 0;
top: 0;
width: 108px;
height: 108px;
margin-left: -54px;
margin-top: -54px;
background: rgba(10, 9, 7, 0.34);
box-sizing: border-box;
border: 2px solid rgba(245, 232, 200, 0.42);
}
#quake-mobile-move-zone .joystick .front {
left: 50%;
top: 50%;
width: 54px;
height: 54px;
margin-left: -27px;
Expand Down Expand Up @@ -2410,7 +2435,7 @@ body.quake-menu-unlocked #quake-weapon {
background: rgba(74, 30, 14, 0.56);
border-color: rgba(232, 154, 72, 0.86);
}
@media (any-pointer: coarse) and (orientation: landscape), (max-width: 960px) and (orientation: landscape) {
@media (any-pointer: coarse), (max-width: 960px) {
body:not(.quake-loading):not(.quake-menu-open):not(.quake-dead):not(.quake-level-complete) #quake-mobile-controls {
display: block;
}
Expand Down
Loading
Loading