Skip to content

Support callbacks in postEvent - #2

Open
nspitko wants to merge 5 commits into
trethaller:masterfrom
nspitko:feat-callbacks
Open

Support callbacks in postEvent#2
nspitko wants to merge 5 commits into
trethaller:masterfrom
nspitko:feat-callbacks

Conversation

@nspitko

@nspitko nspitko commented Jan 23, 2023

Copy link
Copy Markdown

This registers and unregisters the wwise thread every time we get a callback. There's PROBABLY a better way to do this, but for now we'll do the dumb thing and not worry about it.

example syntax:

public static function onSongFinish(evtType: Int, evt: AkEventCallbackInfo )
{
trace ("finished current song, moving to next");
index++;
play();
}
// ....
wwise.Api.postEvent(evt, AkCallbackType.EndOfEvent, onSongFinish);

This registers and unregisters the wwise thread every time we get a callback. There's PROBABLY a better way to do this, but for now we'll do the dumb thing and not worry about it.
@nspitko

nspitko commented Jan 26, 2023

Copy link
Copy Markdown
Author

Minor update to this PR: I fixed postEvent to return its ID so you can disambiguate multiple events using the same callback, and fixed an alignment issue in the struct layout.

@nspitko

nspitko commented Feb 1, 2023

Copy link
Copy Markdown
Author

Ok this has some issues still. It turns out that accessing a non-static member in the callback will cause hl to implode. I'm not quite sure how to solve this yet.

I tried letting haxe create the worker threads but this was a disaster (and I'm not even sure those threads are responsible for firing the callbacks)

The solution may be to just copy the data off to a shared struct and fire them off in the main thread during render, but this will add some latency to them, which is less than ideal. I'm not sure which version is more useful right now.

We have to do some goofy struct wrapping to make this work.
When registering a callback, make sure we're also registering EndOfEvent. This ensures we always know when to clean up the callback, but don't clean it up for other callbacks which may occur earlier.

This fixes a potential crash in registering for multiple callbacks, and a leak when reigstering for callbacks other than EndOfEvent.
@nspitko

nspitko commented Feb 3, 2023

Copy link
Copy Markdown
Author

Ok this should be good. I misunderstood the earlier crash; it has nothing to do with threading and everything to do with vclosures getting GC'd. These changes alloc a struct for us to hl_add_root to, and ensure we clean up buy always registering for AK_EndOfEvent. I've tested to confirm wwise will always fire this event, even when it's stopped via another event.

It's still a bit more convoluted than I'd like, but I don't think there's an easier way to handle all of the edge cases

@;enum abstract -> enum abstract
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.

1 participant