Skip to content

AF Manager class for dynamic animation frame request/cancel#1407

Open
phoenixbf wants to merge 21 commits intoNASA-AMMOS:masterfrom
phoenixbf:master
Open

AF Manager class for dynamic animation frame request/cancel#1407
phoenixbf wants to merge 21 commits intoNASA-AMMOS:masterfrom
phoenixbf:master

Conversation

@phoenixbf
Copy link
Contributor

See #1342

Copy link
Contributor

@gkjohnson gkjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks! A couple comments but I think this is the right direction

@@ -0,0 +1,43 @@
class AFManager {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets call this FrameScheduler for now.

Comment on lines 11 to 21
setXRSession( xrsession ) {

this.xrsession = xrsession;

}

removeXRSession() {

this.xrsession = null;

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When changing the system being used for callbacks we will have to cancel all previous callbacks and reregister them with the new function. Eg if the "LRUCache" schedules an unload event it will be waiting until that event fires before scheduling another one. So if the last event is scheduled using the "xrSession" callback and then the session closes, the scheduled callback will never be fired.

So we'll need to keep track of all scheduled callbacks and rAF handles to swap over the scheduled events.

@gkjohnson
Copy link
Contributor

@phoenixbf - just wanted to check in to see if you had any more questions on the changes needed here.

@phoenixbf
Copy link
Contributor Author

@phoenixbf - just wanted to check in to see if you had any more questions on the changes needed here.

Hi, performing some local testing in order to have a clean rAF tracking system and handling swaps

@phoenixbf
Copy link
Contributor Author

I've added management of pending AF.
It basically keeps track of requested AFs via handle as suggested, providing methods to cancel or flush all pending AFs. When entering XR session, it internally flushes and completes all pending, switching to this.xrsession.requestAnimationFrame for new requests.

So far I tried the above logic in both local and online setups without any evident issues, also with mutiple tsets. If this is the right direction, it should be probably instantiated in TilesRendererBase and then referenced by LRUCache, PriorityQueue, etc. during their initializations

@gkjohnson
Copy link
Contributor

Thanks the direction of this looks great. I think we can cut down on some code redundancy in the implementation but we can deal with that once everything is working.

If this is the right direction, it should be probably instantiated in TilesRendererBase and then referenced by LRUCache, PriorityQueue, etc. during their initializations

This sounds good to me. Looks like the "LRUCache", "PriorityQueue", the "throttle" function, and "QueryManager" are all places where rAF is used (though the throttle function can maybe be changed to "queueMicrotask")

Copy link
Contributor

@gkjohnson gkjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Made a few comments -


setXRSession( xrsession ) {

if ( ! this.framescheduler ) return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should never be "null" so we should be able to remove this check.

this.isLoading = false;

// FrameScheduler referenced by LRUCache, PriorityQueue
this.framescheduler = new FrameScheduler();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets use camel casing to align with the class naming:

this.framescheduler -> this.frameScheduler


this._unloadPriorityCallback = null;

this.framescheduler = null;
Copy link
Contributor

@gkjohnson gkjohnson Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets initialize these to new FrameScheduler() so the classes are in a usable state when constructed. Then we can remove the null checks, as well. This should help the tests pass, too.

@gkjohnson gkjohnson added this to the v0.4.20 milestone Jan 19, 2026
@gkjohnson
Copy link
Contributor

I've just made some of the remaining changes to fix tests, add new tests for FrameScheduler, and address some code styling and other issues. I think this should be ready to merge but if you could test it in a real XR environment that would be great.

@phoenixbf
Copy link
Contributor Author

phoenixbf commented Jan 23, 2026

I've just made some of the remaining changes to fix tests, add new tests for FrameScheduler, and address some code styling and other issues. I think this should be ready to merge but if you could test it in a real XR environment that would be great.

Yep, sure. Today I'll carry out additional online tests with a few HMDs

@gkjohnson gkjohnson modified the milestones: v0.4.20, v0.4.21 Feb 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants