Skip to content
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

Poll Single Event #528

Closed
NamelessPerson opened this issue Aug 24, 2023 · 2 comments
Closed

Poll Single Event #528

NamelessPerson opened this issue Aug 24, 2023 · 2 comments

Comments

@NamelessPerson
Copy link

Currently NetManager can only poll all pending events. However we have logic that may want us to pause processing events after a certain event has been received. It would be helpful to have a PollSingleEvent() or PollEvents(int count) code path.

@RevenantX
Copy link
Owner

@NamelessPerson that events contains not only "receive" events but also disconnect/connect/errors and many others. It's better implement "pause" in application code by storing incoming packets in Queue, and then just process them when your game "unpaused"

@NamelessPerson
Copy link
Author

Yes we thought of that solution, and it is doable but isn't simple with our current architecture. We would need a pretty large refactor to store caching messages and this is complicated by the fact that our other networking backend (steam) is designed around messages NOT being cached.

For the time being I implemented it as such and it appears to be working just fine.

public int PollEvents(int count) {
    if (UnsyncedEvents || count <= 0)
        return 0;
    int eventsCount;
    lock (_netEventsQueue)
        eventsCount = _netEventsQueue.Count;
    eventsCount = Math.Min(count, eventsCount);
    for (int i = 0; i < eventsCount; i++) {
        NetEvent evt;
        lock (_netEventsQueue)
            evt = _netEventsQueue.Dequeue();
        ProcessEvent(evt);
    }
    return eventsCount;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants