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

Static signals #645

Closed
merixstudio opened this issue Mar 25, 2014 · 4 comments
Closed

Static signals #645

merixstudio opened this issue Mar 25, 2014 · 4 comments

Comments

@merixstudio
Copy link

All signals could be static and not as instance members. This would allow for greater modularity of game developer's code and doesn't require to pass everywhere a Game instance.

Instead of this:

// Inside Phaser.Loader constructor
this.onFileComplete = new Phaser.Signal();

Could be this:

Phaser.Loader.onFileComplete = new Phaser.Signal();

All loaders and other parts of the Phaser code should then use these global signals, eventually passing game instance as an argument to callbacks.

Then third-party additions to Phaser (e.g. custom loaders) would use these global signals instead of inventing their own ones.

Global signals are implemented in the Django web framework like this and it greatly helps to decouple modules. Note that Django is not game development tool, but contains very similar signals like in Phaser.

@photonstorm
Copy link
Collaborator

The reason we didn't adopt this approach is because ultimately we want (and need) to support multiple Phaser instances running on the same page, which this approach doesn't allow for. Obviously not an issue for the likes of Django, but would be a big one for us.

@merixstudio
Copy link
Author

No, no, it's the other way around. Static signals would definitely ease implementing generic plugins in cases when there are many Phaser instances on one page. For example without knowing if there are any game instances or how many of them are on a page, would be possible to write something like this (not very practical but hopefully illustrates the idea):

memoryUsage = 0;  // Will hold memory usage in bytes among all game instances.

Phaser.Loader.onFileComplete.add(function(game, file) {
    // Assuming `file` is an image.
    if (file.width && file.height)
        memoryUsage += file.width * file.height * 4;
});

Currently it's very hard to write such code. Loader signals are created only after game's preload method is run.

You guys are probably concerned about that signal receivers list will be global among all games. This is true, but it'a also not a problem. Game developers should not modify signal receivers in anyway. Phaser's code also should not interact with receiver list directly.

Consider also implementing senders, it would allow to connect to a signal only when some conditions are met (then above example code could be stripped from the if statement).

Anyway thanks for your time. The whole idea is rather big change and definitely a feature request and it's not very important. You guys surely have a lot of work (doing very good job!), but implementing this idea someday won't limit Phaser in anyway, but it would allow for easier extendability.

@georgiee
Copy link
Contributor

Merixstudio's description sounds good to me. And by passing the game instance along allows to distinct the different phaser instances, doesn't it ?

@photonstorm
Copy link
Collaborator

This feature request has been moved to the Phaser 3 feature list (so is being closed here)

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