#2126 closed enhancement (fixed)
[PATCH] Switch GameView scripting to global functions
Reported by: | Yves | Owned by: | Yves |
---|---|---|---|
Priority: | Should Have | Milestone: | Alpha 15 |
Component: | Core engine | Keywords: | Spidermonkey |
Cc: | Yves | Patch: |
Description
Some background
As described in the Spidermonkey upgrade forum thread the plan is to switch from CJSObject to mainly using global functions for the scripting interface.
So instead of exposing an object with properties to scripts, we do it with global functions:
// before gameView.Culling = false; // after Engine.GameView_SetCullingEnabled(false);
CJSObject was used much more in the earlier Simulation implementation but the consensus was that it might look a little cleaner in the scripting part but this is not worth the additional complexity. We have some places where we really need to expose C++ objects to JS but in this case we don't use the CJSObject implementation. An additional problem with CJSObject is that it's very hard to understand and according to Philip even caused compiler issues because it uses some very special constructs (if I remember correctly).
What this patch does
The patch attached switches GameView from CJSObject to global functions. There are still some other uses of CJSObject, so we can't remove it yet. In my working copy I have switched most of the other modules using CJSObject and I plan to create additional patches for those.
Same approach as SoundManager
Also check this post and how stwf has implemented it in the SoundManager. I'm using the same approach to make it as consistent as possible across the different modules. I haven't yet found a better solution than checking if g_Game and g_Game->GetView are valid pointers in each setter/getter.
Macros:
I think they are appropriate here for the reasons listed below but I'm also open for other suggestions.
- They enforce some consistency in naming which should make it easier to find the right function in JS.
- It expresses the relation between the naming of setters and getters in the GameView class and in the interface files (JSInterface_GameView.*)
- It makes the code a little more difficult to understand, but it shouldn't be too difficult because it's only used for some simple getters and setters.
- It reduces code duplication.
I'd like to hear some comments before committing it.
Attachments (1)
Change History (6)
comment:1 by , 11 years ago
Cc: | added |
---|
by , 11 years ago
Attachment: | gameview_global_functions_v1.0.diff added |
---|
comment:2 by , 11 years ago
comment:4 by , 11 years ago
Keywords: | review removed |
---|
RedFox did a quick review on IRC.