-
Notifications
You must be signed in to change notification settings - Fork 706
TEST PR Refactor/webgl border layer #2451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
evanpelle
wants to merge
14
commits into
openfrontio:main
Choose a base branch
from
scamiv:refactor/webgl-border-layer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a0552a8
Introduce BorderRenderer abstraction
scamiv b261a54
Add drawsOwnBorders method to BorderRenderer interface
scamiv 2a0c832
Add Territory WebGL rendering toggle and status UI
scamiv 576905d
Add debug border toggle for Territory WebGL rendering
scamiv ee21881
Enhance Territory WebGL rendering with border relation flags
scamiv fae08ab
Increase initial chunk capacity in TerritoryBorderWebGL and add debug…
scamiv 66cb96f
Integrate FrameProfiler for enhanced performance tracking in GameRend…
scamiv 34063e5
Optimize TerritoryLayer rendering by skipping unnecessary canvas upda…
scamiv b9551a2
Refactor PlayerInfoOverlay and TerritoryLayer for improved hover func…
scamiv 5976fbb
Use isValidCoord() to check tile validity
scamiv 512b75f
- **Added profiling to `WebGLBorderRenderer`**
scamiv fa4c195
Add copy functionality to PerformanceOverlay for JSON snapshot of per…
scamiv 5f3c035
actually use the flag _maybeStaleBorder (renamed from wrong _isBorder…
scamiv 5bf255f
skip paintPlayerBorder calls on focusedPlayer change if borderRendere…
scamiv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| export class FrameProfiler { | ||
| private static timings: Record<string, number> = {}; | ||
|
|
||
| /** | ||
| * Clear all accumulated timings for the current frame. | ||
| */ | ||
| static clear(): void { | ||
| this.timings = {}; | ||
| } | ||
|
|
||
| /** | ||
| * Record a duration (in ms) for a named span. | ||
| */ | ||
| static record(name: string, duration: number): void { | ||
| if (!Number.isFinite(duration)) return; | ||
| this.timings[name] = (this.timings[name] ?? 0) + duration; | ||
| } | ||
|
|
||
| /** | ||
| * Convenience helper to start a span. | ||
| * Returns a high-resolution timestamp to be passed into end(). | ||
| */ | ||
| static start(): number { | ||
| return performance.now(); | ||
| } | ||
|
|
||
| /** | ||
| * Convenience helper to end a span started with start(). | ||
| */ | ||
| static end(name: string, startTime: number): void { | ||
| const duration = performance.now() - startTime; | ||
| this.record(name, duration); | ||
| } | ||
|
|
||
| /** | ||
| * Consume and reset all timings collected so far. | ||
| */ | ||
| static consume(): Record<string, number> { | ||
| const copy = { ...this.timings }; | ||
| this.timings = {}; | ||
| return copy; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { UnitType } from "../../core/game/Game"; | ||
| import { TileRef } from "../../core/game/GameMap"; | ||
| import { GameView, PlayerView, UnitView } from "../../core/game/GameView"; | ||
|
|
||
| const HOVER_UNIT_TYPES: UnitType[] = [ | ||
| UnitType.Warship, | ||
| UnitType.TradeShip, | ||
| UnitType.TransportShip, | ||
| ]; | ||
| const HOVER_DISTANCE_PX = 5; | ||
|
|
||
| function euclideanDistWorld( | ||
| coord: { x: number; y: number }, | ||
| tileRef: TileRef, | ||
| game: GameView, | ||
| ): number { | ||
| const x = game.x(tileRef); | ||
| const y = game.y(tileRef); | ||
| const dx = coord.x - x; | ||
| const dy = coord.y - y; | ||
| return Math.sqrt(dx * dx + dy * dy); | ||
| } | ||
|
|
||
| function distSortUnitWorld( | ||
| coord: { x: number; y: number }, | ||
| game: GameView, | ||
| ): (a: UnitView, b: UnitView) => number { | ||
| return (a, b) => { | ||
| const distA = euclideanDistWorld(coord, a.tile(), game); | ||
| const distB = euclideanDistWorld(coord, b.tile(), game); | ||
| return distA - distB; | ||
| }; | ||
| } | ||
|
|
||
| export interface HoverTargetResolution { | ||
| player: PlayerView | null; | ||
| unit: UnitView | null; | ||
| } | ||
|
|
||
| export function resolveHoverTarget( | ||
| game: GameView, | ||
| worldCoord: { x: number; y: number }, | ||
| ): HoverTargetResolution { | ||
| const tile = game.ref(worldCoord.x, worldCoord.y); | ||
| if (!tile) { | ||
| return { player: null, unit: null }; | ||
| } | ||
|
|
||
| const owner = game.owner(tile); | ||
| if (owner && owner.isPlayer()) { | ||
| return { player: owner as PlayerView, unit: null }; | ||
| } | ||
|
|
||
| if (game.isLand(tile)) { | ||
| return { player: null, unit: null }; | ||
| } | ||
|
|
||
| const units = game | ||
| .units(...HOVER_UNIT_TYPES) | ||
| .filter( | ||
| (u) => euclideanDistWorld(worldCoord, u.tile(), game) < HOVER_DISTANCE_PX, | ||
| ) | ||
| .sort(distSortUnitWorld(worldCoord, game)); | ||
|
|
||
| if (units.length > 0) { | ||
| return { player: units[0].owner(), unit: units[0] }; | ||
| } | ||
|
|
||
| return { player: null, unit: null }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { TileRef } from "../../../core/game/GameMap"; | ||
| import { PlayerView } from "../../../core/game/GameView"; | ||
|
|
||
| export interface BorderRenderer { | ||
| setAlternativeView(enabled: boolean): void; | ||
| setHoveredPlayerId(playerSmallId: number | null): void; | ||
| drawsOwnBorders(): boolean; | ||
|
|
||
| updateBorder( | ||
| tile: TileRef, | ||
| owner: PlayerView | null, | ||
| isBorder: boolean, | ||
| isDefended: boolean, | ||
| hasFallout: boolean, | ||
| ): void; | ||
|
|
||
| clearTile(tile: TileRef): void; | ||
|
|
||
| render(context: CanvasRenderingContext2D): void; | ||
| } | ||
|
|
||
| export class NullBorderRenderer implements BorderRenderer { | ||
| drawsOwnBorders(): boolean { | ||
| return false; | ||
| } | ||
|
|
||
| setAlternativeView() {} | ||
|
|
||
| setHoveredPlayerId() {} | ||
|
|
||
| updateBorder() {} | ||
|
|
||
| clearTile() {} | ||
|
|
||
| render() {} | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.