Collision Zone Performance Refactor [SYNTH-132]#1354
Conversation
[SYNTH-132]
ead903f to
9468a61
Compare
AlexD717
left a comment
There was a problem hiding this comment.
The protected zone collisions seem to be triggering when they are not supposed to sometimes (had it happen multiple times but doesn't happen every time)
Fission._.Synthesis.-.Google.Chrome.2026-07-10.11-08-50.-.Trim.mp4
rutmanz
left a comment
There was a problem hiding this comment.
I'm only requesting changes for the acronyms. Also because I could reproduce Alexey's issue with premature contact penalties
| // Remove from any scoring zones | ||
| const zones = World.sceneRenderer.filterSceneObjects(x => x instanceof ScoringZoneSceneObject) | ||
| zones.forEach(x => { | ||
| if (this._gamePieceBodyId) ScoringZoneSceneObject.removeGamepiece(x, this._gamePieceBodyId) | ||
| }) | ||
|
|
There was a problem hiding this comment.
what was the original purpose of this
There was a problem hiding this comment.
It was old game pieces removing themselves from old scoring zones. I don't know why this would ever be needed, but we're doing things in such a way that this couldn't ever be necessary.
Plus, the function being called here wouldn't even work, since it compares objects of different origin by reference.
Co-Authored-By: Zach Rutman <zachary.rutman@autodesk.com>
d8532ca to
d9ff69e
Compare
c6f942d to
76be4b5
Compare
| private generateVisualProperties(): VisualProperties | undefined { | ||
| // `GetWorldTransform` returns a reference, destroying it causes a memory out of bounds later | ||
| const newTransform = World.physicsSystem.getBody(this.parentBodyId!)!.GetWorldTransform() | ||
| const transformHasNotUpdated = | ||
| this._cachedFieldTransformation && newTransform.Equals(this._cachedFieldTransformation) | ||
|
|
||
| // Update translation, rotation, and scale only if the field has moved | ||
| if (transformHasNotUpdated && !this._deltaTransHasUpdated) return undefined | ||
|
|
||
| if (this._cachedFieldTransformation) JOLT.destroy(this._cachedFieldTransformation) | ||
| this._cachedFieldTransformation = newTransform | ||
| this._deltaTransHasUpdated = false |
| import type Jolt from "@azaleacolburn/jolt-physics" | ||
| import * as THREE from "three" | ||
| import Pako from "pako" | ||
| import World from "@/systems/World" |
Task
SYNTH-132
Symptom
Performance tanks when robots and pieces enter zones. Generally zones cause poor performance.
This is due to the way in which
ZoneSceneObjects handle collisions. Basically, each one creates a sensor, then subscribes to every collision between all Jolt bodies, this is horribly expensive for two reasons:Solution
Each sub-class of
ZoneSceneObjectnow implements a function calledcheckObjectsInZone, which is responsible for manually going through every object that the zone cares about and checking if they are in the zone, then performing the needed actions given that information.Instead of listening for collisions, these functions (in
ScoringZoneSceneObjectandProtectedZoneSceneObject) draw bounding boxes around every object they care about (e.g. each robot), then check if that bounding box overlaps with that of the zone.Verification
We don't have standardized performance benchmarks, but the lag that used to be present when a robot enters a protected zone is gone. Try this with 2471's 2018 bot, the difference is actually huge (on my machine).
The performance for game pieces in scoring zones is gone, however on some fields (e.g. 2023), there complicated jolt bodies around the scoring zone, which can cause placed bodies to lag slightly. However, other parts of the scoring zone are unaffected.
Tests have been updated to match the new way zones work.
Before merging, ensure the following criteria are met: