Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#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.

  1. They enforce some consistency in naming which should make it easier to find the right function in JS.
  2. It expresses the relation between the naming of setters and getters in the GameView class and in the interface files (JSInterface_GameView.*)
  3. 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.
  4. It reduces code duplication.

I'd like to hear some comments before committing it.

Attachments (1)

gameview_global_functions_v1.0.diff (10.1 KB ) - added by Yves 11 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 by Yves, 11 years ago

Cc: Yves added

comment:2 by Yves, 11 years ago

RedFox did a quick review on IRC.

comment:3 by Yves, 11 years ago

Resolution: fixed
Status: newclosed

In 13826:

Changes GameView to expose global functions to scripts instead of using CJSObject.
Fixes #2126
Refs #1886

comment:4 by leper, 11 years ago

Keywords: review removed

comment:5 by Yves, 11 years ago

In 14026:

Remove ScriptableObject/CJSObject

Since all remaining uses of ScriptableObject/CJSObject have been removed, the related files can now also be removed.
Closes #2212
Refs #2126
Refs #2137
Refs #1886

Note: See TracTickets for help on using tickets.