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

[Server] Suggest using IEnumerable for EmitClients instead of array in core implementation #709

Open
duydang2311 opened this issue Oct 13, 2022 · 0 comments

Comments

@duydang2311
Copy link
Contributor

duydang2311 commented Oct 13, 2022

As for now, the Alt.EmitClients takes IPlayer[] as its first argument.
It seems better to prefer IEnumerable<IPlayer> here, so in piece of code like below example can avoid creating a new array with ToArray.

After having a look at the core implementation, I think this change can be made into the core, as a foreach loop can replace the for one https://github.com/FabianTerhorst/coreclr-module/blob/dev/api/AltV.Net/Core.cs#L343.
Plus, this change also doesn't break anything because IEnumerable is array base type.

Example where an extra array must be created to satisfy EmitClients first argument:

public void BroadcastMessage(Predicate<AltIPlayer> predicate, string color, string message)
{
	var players = new LinkedList<AltIPlayer>();
	foreach (var p in Alt.GetAllPlayers())
	{
		if (predicate(p))
		{
			players.AddLast(p);
		}
	}
	Alt.EmitClients(players.ToArray(), "chat.message", color, message);
}

If it's reasonable, I can try working on this.

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

No branches or pull requests

1 participant