Stack, Snake and Hop re-tessellate rounded rectangles every frame

Đang mở
#35 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
55/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
game-dev, performance

Hướng nghiên cứu

Start by reading the drawing code in games/stack/scenes/GameScene.ts, games/snake/scenes/GameScene.ts, and games/hop/scenes/GameScene.ts, then compare it with the sparkTexture example in shared/ui.ts. Run npm run dev and use a Performance trace to check how frame time changes as the Stack board fills or the Snake grows. The issue is done when drawing cost no longer measurably grows with board fill or snake length and the visuals remain unchanged; run npm run typecheck and npm run build.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

help wanted performance severity: medium

Summary

Three games clear a Graphics object and redraw every cell or segment with fillRoundedRect each frame. Phaser's WebGL Graphics renderer tessellates each arc with a fixed step and does not cache geometry, so cost grows with board fill and snake length.

Where

  • games/stack/scenes/GameScene.ts:458-497, games/stack/scenes/GameScene.ts:500-512 (three rounded rects per cell)
  • games/snake/scenes/GameScene.ts:437-452, games/snake/scenes/GameScene.ts:404-412 (two per segment plus three colour objects)
  • games/hop/scenes/GameScene.ts:396-435

Details

Estimated from the Phaser 3.90 source, not measured in a browser:

  • A rounded rect is about 400 points and 400 triangles.
  • Stack with about 100 visible cells: about 300 paths and 120,000 point allocations per frame.
  • Snake at length 50: about 40,000 allocations and triangles per frame.

Impact

Likely GC pauses and dropped frames on phones and low-end laptops, worst when the Stack board is full or the snake is long, which is when timing matters most.

Steps to reproduce

  1. Play Stack until the board is half full, or Snake to length 50.
  2. Record a Performance trace and compare scripting time and minor GC frequency with the start of the run.

Suggested fix

Pre-render one white cell texture with generateTexture (as sparkTexture in shared/ui.ts already does) and draw cells as pooled tinted Images, or stamp into a RenderTexture updated only when the board changes. Cache Snake's gradient colours per length. A cheaper stopgap is fillRect for the glow and highlight layers.

Acceptance criteria

  • Frame time in Stack and Snake does not grow measurably with board fill or snake length
  • Visuals are unchanged

Getting started

  • Relevant files: games/stack/scenes/GameScene.ts, games/snake/scenes/GameScene.ts, games/hop/scenes/GameScene.ts, shared/ui.ts
  • Run locally: npm install, then npm run dev
  • Checks: npm run typecheck and npm run build (there is no test suite yet)
  • Related docs: README.md

Filed by repo-audit/full-audit at b001f5d. Severity: medium. Effort: M. audit-key: performance|games/stack/scenes/GameScene.ts|drawCell

Ngôn ngữ chính
TypeScript
Star
3
Fork
3
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TMHSDigital/GH-Arcade

Tất cả issue của TMHSDigital/GH-Arcade

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.