feat: boot-экран, стабильность Windows и оптимизация Pixi/пульта
- Экран загрузки (boot.html, bootWindow): статусы, ensureRoots и проверка лицензии, редактор после готовности; закрытие через destroy при closable:false. - Упакованное приложение на Windows: disableHardwareAcceleration, sandbox выкл. вне dev, отложенный показ редактора, ensureWindowBecomesVisible, фокус на splash при second-instance. - Vite: вход boot.html; eslint: игнор release/; тесты boot и maxFPS тикера. - Пульт: позиция курсора кисти через ref/DOM без setState на каждый move; черновик эффекта через rAF; Pixi: maxFPS 32, resolution cap, antialias off, debounce ResizeObserver, меньше частиц poisonCloud, contain на хосте. Made-with: Cursor
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
<!doctype html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src 'self' data:; style-src 'unsafe-inline';" />
|
||||
<title>Загрузка</title>
|
||||
<style>
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
html,
|
||||
body {
|
||||
margin: 0;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
font-family:
|
||||
ui-sans-serif,
|
||||
system-ui,
|
||||
'Segoe UI',
|
||||
Roboto,
|
||||
'Helvetica Neue',
|
||||
Arial,
|
||||
sans-serif;
|
||||
background: #09090b;
|
||||
color: #fafafa;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
.wrap {
|
||||
display: flex;
|
||||
min-height: 100%;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 28px 24px;
|
||||
background:
|
||||
radial-gradient(ellipse 120% 80% at 50% -20%, rgba(99, 102, 241, 0.18), transparent 55%),
|
||||
radial-gradient(ellipse 90% 60% at 100% 100%, rgba(168, 85, 247, 0.1), transparent 45%),
|
||||
#09090b;
|
||||
}
|
||||
.card {
|
||||
width: 100%;
|
||||
max-width: 360px;
|
||||
text-align: center;
|
||||
padding: 32px 28px 28px;
|
||||
border-radius: 16px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||
background: rgba(24, 24, 27, 0.85);
|
||||
box-shadow:
|
||||
0 0 0 1px rgba(0, 0, 0, 0.35) inset,
|
||||
0 24px 48px rgba(0, 0, 0, 0.45);
|
||||
backdrop-filter: blur(12px);
|
||||
}
|
||||
.logo {
|
||||
width: 72px;
|
||||
height: 72px;
|
||||
margin: 0 auto 16px;
|
||||
display: block;
|
||||
border-radius: 18px;
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
|
||||
}
|
||||
.title {
|
||||
margin: 0 0 6px;
|
||||
font-size: 1.35rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: -0.02em;
|
||||
line-height: 1.2;
|
||||
}
|
||||
.subtitle {
|
||||
margin: 0 0 22px;
|
||||
font-size: 0.875rem;
|
||||
color: #a1a1aa;
|
||||
font-weight: 400;
|
||||
}
|
||||
.version {
|
||||
margin: 0 0 20px;
|
||||
font-size: 0.75rem;
|
||||
color: #71717a;
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
.status {
|
||||
margin: 0 0 18px;
|
||||
font-size: 0.9rem;
|
||||
color: #e4e4e7;
|
||||
min-height: 1.4em;
|
||||
line-height: 1.4;
|
||||
}
|
||||
.bar {
|
||||
height: 3px;
|
||||
border-radius: 999px;
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
overflow: hidden;
|
||||
}
|
||||
.bar::after {
|
||||
content: '';
|
||||
display: block;
|
||||
height: 100%;
|
||||
width: 32%;
|
||||
border-radius: inherit;
|
||||
background: linear-gradient(90deg, #6366f1, #a855f7);
|
||||
animation: boot-indeterminate 1.2s ease-in-out infinite;
|
||||
}
|
||||
@keyframes boot-indeterminate {
|
||||
0% {
|
||||
transform: translateX(-120%);
|
||||
}
|
||||
100% {
|
||||
transform: translateX(380%);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="wrap">
|
||||
<div class="card">
|
||||
<img class="logo" src="./app-window-icon.png" width="72" height="72" alt="" />
|
||||
<h1 class="title" data-boot-title>DNDGamePlayer</h1>
|
||||
<p class="subtitle">редактор и проигрыватель</p>
|
||||
<p class="version" data-boot-version></p>
|
||||
<p class="status" id="boot-status">Запуск…</p>
|
||||
<div class="bar" aria-hidden="true"></div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -222,6 +222,7 @@
|
||||
.brushCursor {
|
||||
position: absolute;
|
||||
z-index: 2;
|
||||
will-change: left, top;
|
||||
transform: translate(-50%, -50%);
|
||||
border-radius: 50%;
|
||||
border: 1px solid rgba(255, 255, 255, 0.55);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import React, { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
||||
|
||||
import { pickEraseTargetId } from '../../shared/effectEraserHitTest';
|
||||
import { ipcChannels } from '../../shared/ipc/contracts';
|
||||
@@ -62,7 +62,6 @@ export function ControlApp() {
|
||||
points?: { x: number; y: number; tMs: number }[];
|
||||
} | null>(null);
|
||||
const [draftFxTick, setDraftFxTick] = useState(0);
|
||||
const [cursorN, setCursorN] = useState<{ x: number; y: number } | null>(null);
|
||||
const [previewSize, setPreviewSize] = useState<{ w: number; h: number }>({ w: 1, h: 1 });
|
||||
const [previewContentRect, setPreviewContentRect] = useState<{
|
||||
x: number;
|
||||
@@ -70,6 +69,13 @@ export function ControlApp() {
|
||||
w: number;
|
||||
h: number;
|
||||
} | null>(null);
|
||||
const previewContentRectRef = useRef(previewContentRect);
|
||||
previewContentRectRef.current = previewContentRect;
|
||||
const previewSizeRef = useRef(previewSize);
|
||||
previewSizeRef.current = previewSize;
|
||||
const brushCursorElRef = useRef<HTMLDivElement | null>(null);
|
||||
const cursorPosRef = useRef<{ x: number; y: number } | null>(null);
|
||||
const draftPaintRafRef = useRef(0);
|
||||
|
||||
useEffect(() => {
|
||||
void api.invoke(ipcChannels.project.get, {}).then((res) => {
|
||||
@@ -351,12 +357,58 @@ export function ControlApp() {
|
||||
}, [currentGraphNodeId, project]);
|
||||
|
||||
const tool = fxState?.tool ?? { tool: 'fog', radiusN: 0.08, intensity: 0.6 };
|
||||
const toolRef = useRef(tool);
|
||||
toolRef.current = tool;
|
||||
|
||||
function layoutBrushCursor(): void {
|
||||
const el = brushCursorElRef.current;
|
||||
const p = cursorPosRef.current;
|
||||
const cr = previewContentRectRef.current;
|
||||
const ps = previewSizeRef.current;
|
||||
const t = toolRef.current;
|
||||
if (!el) return;
|
||||
if (!p) {
|
||||
el.style.visibility = 'hidden';
|
||||
return;
|
||||
}
|
||||
el.style.visibility = 'visible';
|
||||
const ox = cr ? cr.x : 0;
|
||||
const oy = cr ? cr.y : 0;
|
||||
const cw = cr ? cr.w : ps.w;
|
||||
const ch = cr ? cr.h : ps.h;
|
||||
const minDim = Math.min(cw, ch);
|
||||
const size = Math.max(2, t.radiusN * minDim * 2);
|
||||
el.style.left = `${String(ox + p.x * cw)}px`;
|
||||
el.style.top = `${String(oy + p.y * ch)}px`;
|
||||
el.style.width = `${String(size)}px`;
|
||||
el.style.height = `${String(size)}px`;
|
||||
}
|
||||
|
||||
function scheduleDraftRepaint(): void {
|
||||
if (draftPaintRafRef.current !== 0) return;
|
||||
draftPaintRafRef.current = requestAnimationFrame(() => {
|
||||
draftPaintRafRef.current = 0;
|
||||
setDraftFxTick((x) => x + 1);
|
||||
});
|
||||
}
|
||||
|
||||
useLayoutEffect(() => {
|
||||
layoutBrushCursor();
|
||||
}, [tool.radiusN, previewContentRect, previewSize.w, previewSize.h]);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (draftPaintRafRef.current !== 0) {
|
||||
cancelAnimationFrame(draftPaintRafRef.current);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
function toNPoint(e: React.PointerEvent): { x: number; y: number } | null {
|
||||
const host = previewHostRef.current;
|
||||
if (!host) return null;
|
||||
const r = host.getBoundingClientRect();
|
||||
const cr = previewContentRect;
|
||||
const cr = previewContentRectRef.current;
|
||||
const ox = cr ? cr.x : 0;
|
||||
const oy = cr ? cr.y : 0;
|
||||
const cw = cr ? cr.w : r.width;
|
||||
@@ -914,45 +966,29 @@ export function ControlApp() {
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
{cursorN ? (
|
||||
<div
|
||||
className={styles.brushCursor}
|
||||
style={{
|
||||
left:
|
||||
(previewContentRect ? previewContentRect.x : 0) +
|
||||
cursorN.x * (previewContentRect ? previewContentRect.w : previewSize.w),
|
||||
top:
|
||||
(previewContentRect ? previewContentRect.y : 0) +
|
||||
cursorN.y * (previewContentRect ? previewContentRect.h : previewSize.h),
|
||||
width:
|
||||
tool.radiusN *
|
||||
Math.min(
|
||||
previewContentRect ? previewContentRect.w : previewSize.w,
|
||||
previewContentRect ? previewContentRect.h : previewSize.h,
|
||||
) *
|
||||
2,
|
||||
height:
|
||||
tool.radiusN *
|
||||
Math.min(
|
||||
previewContentRect ? previewContentRect.w : previewSize.w,
|
||||
previewContentRect ? previewContentRect.h : previewSize.h,
|
||||
) *
|
||||
2,
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
<div
|
||||
ref={brushCursorElRef}
|
||||
className={styles.brushCursor}
|
||||
style={{ visibility: 'hidden' }}
|
||||
aria-hidden
|
||||
/>
|
||||
<div
|
||||
className={styles.brushLayer}
|
||||
onPointerEnter={(e) => {
|
||||
const p = toNPoint(e);
|
||||
if (!p) return;
|
||||
setCursorN(p);
|
||||
cursorPosRef.current = p;
|
||||
layoutBrushCursor();
|
||||
}}
|
||||
onPointerLeave={() => {
|
||||
cursorPosRef.current = null;
|
||||
layoutBrushCursor();
|
||||
}}
|
||||
onPointerLeave={() => setCursorN(null)}
|
||||
onPointerDown={(e) => {
|
||||
const p = toNPoint(e);
|
||||
if (!p) return;
|
||||
setCursorN(p);
|
||||
cursorPosRef.current = p;
|
||||
layoutBrushCursor();
|
||||
(e.currentTarget as HTMLDivElement).setPointerCapture(e.pointerId);
|
||||
if (tool.tool === 'eraser') {
|
||||
const id = pickEraseTargetId(fxState?.instances ?? [], p, tool.radiusN);
|
||||
@@ -969,7 +1005,8 @@ export function ControlApp() {
|
||||
onPointerMove={(e) => {
|
||||
const p = toNPoint(e);
|
||||
if (!p) return;
|
||||
setCursorN(p);
|
||||
cursorPosRef.current = p;
|
||||
layoutBrushCursor();
|
||||
if (tool.tool === 'eraser' && (e.buttons & 1) !== 0) {
|
||||
const id = pickEraseTargetId(fxState?.instances ?? [], p, tool.radiusN);
|
||||
if (id) void fx.dispatch({ kind: 'instance.remove', id });
|
||||
@@ -984,7 +1021,7 @@ export function ControlApp() {
|
||||
const minStep = Math.max(0.004, tool.radiusN * 0.25);
|
||||
if (dx * dx + dy * dy < minStep * minStep) return;
|
||||
b.points.push({ x: p.x, y: p.y, tMs: Date.now() });
|
||||
setDraftFxTick((x) => x + 1);
|
||||
scheduleDraftRepaint();
|
||||
}}
|
||||
onPointerUp={() => {
|
||||
void commitStroke();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
.host {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
contain: layout paint;
|
||||
}
|
||||
|
||||
.hostInteractive {
|
||||
|
||||
@@ -10,3 +10,8 @@ void test('PxiEffectsOverlay: canvas не перехватывает указа
|
||||
const src = fs.readFileSync(path.join(here, 'PxiEffectsOverlay.tsx'), 'utf8');
|
||||
assert.ok(src.includes("app.canvas.style.pointerEvents = interactive ? 'auto' : 'none'"));
|
||||
});
|
||||
|
||||
void test('PxiEffectsOverlay: ограничение FPS тикера для нагрузки', () => {
|
||||
const src = fs.readFileSync(path.join(here, 'PxiEffectsOverlay.tsx'), 'utf8');
|
||||
assert.ok(src.includes('app.ticker.maxFPS'));
|
||||
});
|
||||
|
||||
@@ -41,13 +41,15 @@ export function PixiEffectsOverlay({ state, interactive = false, style, viewport
|
||||
const viewportRef = useRef<{ x: number; y: number; w: number; h: number }>({ x: 0, y: 0, w: 1, h: 1 });
|
||||
const viewportProvidedRef = useRef(false);
|
||||
|
||||
const dpr = useMemo(() => Math.min(2, window.devicePixelRatio || 1), []);
|
||||
/** Снижаем resolution на HiDPI — меньше пикселей в WebGL, визуально ок для оверлея эффектов. */
|
||||
const dpr = useMemo(() => Math.min(1.5, window.devicePixelRatio || 1), []);
|
||||
|
||||
useEffect(() => {
|
||||
const host = hostRef.current;
|
||||
if (!host) return;
|
||||
|
||||
let destroyed = false;
|
||||
let resizeRaf = 0;
|
||||
let app: any = null;
|
||||
let cleanup: (() => void) | null = null;
|
||||
void (async () => {
|
||||
@@ -58,10 +60,14 @@ export function PixiEffectsOverlay({ state, interactive = false, style, viewport
|
||||
app = new pixi.Application();
|
||||
await app.init({
|
||||
backgroundAlpha: 0,
|
||||
antialias: true,
|
||||
antialias: false,
|
||||
powerPreference: 'high-performance',
|
||||
resolution: dpr,
|
||||
autoDensity: true,
|
||||
preference: 'webgl',
|
||||
});
|
||||
// Меньше кадров — меньше CPU/GPU; анимации эффектов остаются плавными.
|
||||
app.ticker.maxFPS = 32;
|
||||
if (destroyed) return;
|
||||
host.appendChild(app.canvas);
|
||||
// Canvas по умолчанию перехватывает hit-test; оставляем клики «сквозь» оверлей для слоя кисти сверху.
|
||||
@@ -72,13 +78,16 @@ export function PixiEffectsOverlay({ state, interactive = false, style, viewport
|
||||
app.stage.addChild(root);
|
||||
|
||||
const ro = new ResizeObserver(() => {
|
||||
const r = host.getBoundingClientRect();
|
||||
app.renderer.resize(Math.max(1, Math.floor(r.width)), Math.max(1, Math.floor(r.height)));
|
||||
sizeRef.current = { w: app.renderer.width, h: app.renderer.height };
|
||||
if (!viewportProvidedRef.current) {
|
||||
viewportRef.current = { x: 0, y: 0, w: sizeRef.current.w, h: sizeRef.current.h };
|
||||
}
|
||||
syncNodes(pixi, root, nodesRef.current, stateRef.current, sizeRef.current, viewportRef.current);
|
||||
cancelAnimationFrame(resizeRaf);
|
||||
resizeRaf = requestAnimationFrame(() => {
|
||||
const r = host.getBoundingClientRect();
|
||||
app.renderer.resize(Math.max(1, Math.floor(r.width)), Math.max(1, Math.floor(r.height)));
|
||||
sizeRef.current = { w: app.renderer.width, h: app.renderer.height };
|
||||
if (!viewportProvidedRef.current) {
|
||||
viewportRef.current = { x: 0, y: 0, w: sizeRef.current.w, h: sizeRef.current.h };
|
||||
}
|
||||
syncNodes(pixi, root, nodesRef.current, stateRef.current, sizeRef.current, viewportRef.current);
|
||||
});
|
||||
});
|
||||
ro.observe(host);
|
||||
|
||||
@@ -117,6 +126,7 @@ export function PixiEffectsOverlay({ state, interactive = false, style, viewport
|
||||
|
||||
return () => {
|
||||
destroyed = true;
|
||||
cancelAnimationFrame(resizeRaf);
|
||||
cleanup?.();
|
||||
const a = appRef.current;
|
||||
appRef.current = null;
|
||||
@@ -378,7 +388,8 @@ function createInstanceNode(
|
||||
if (inst.type === 'poisonCloud') {
|
||||
const cont = new pixi.Container();
|
||||
const tex = getPoisonParticleTexture(pixi);
|
||||
const particleCount = 520;
|
||||
/** Меньше спрайтов — быстрее тик; картина остаётся плотной. */
|
||||
const particleCount = 400;
|
||||
const particles: PoisonParticleFx[] = [];
|
||||
for (let i = 0; i < particleCount; i += 1) {
|
||||
const s = new pixi.Sprite(tex);
|
||||
|
||||
Reference in New Issue
Block a user