[Feature Request] First class functions

Post » Fri Mar 31, 2017 3:23 pm

Overall I am a little bit disappointed how Construct 3 is THE SAME as Construct 2, concerning "langugage" features (not development utilities, where it gets much better). Not to belittle the huge amount of work done to rewrite the whole editor to browser, that is HUGE and I am amazed how little bugs are in the beta. (I imported a project with aroung 1000 events and no problem, runs very nice).

But I suggest also adding a new feature to the "language" - better support for functions.

Problem statement / motivation
Readability of code: Function created with Function plugin are second class. They do not provide comparable aids during development as "first class" system functions, such as lerp, choose, etc. - no parameter and type hinting, they must be called specially by Function.Call (xxx) expressions. Moreover they can be placed anywhere in any event sheet (even not included ones), they are hard to find in large projects.

Performance: Function calling carries currently relatively huge overhead. I am able to do approx. 70.000 actions per frame (with 60 fps) on my hardware, but only approx. 6.000 function calls. The overhead of a function call is BIG - 10x simple action, such as manipulating a variable.
Edit2: I just performed similar measurement in App Game Kit (AGK) engine, and just for comparison (and how much we pay for visual development / javascript backend in Construct) - results are 7.200.000 simple actions per frame (manipulating instance variables), 3.150.000 function calls per frame when keeping 60 fps.

Suggested behaviour: Lets have them as a members of Object Type and Family. The same way these objects can have instance variables, let them also have functions. When adding a function, one must specify the names and types of parameters, possibly also function and parameter descriptions, that can be shown in editor and expressions. The parameter types also allow for typechecking of calls in editor.
Such functions can be directly called by Object type.Function name (Param 0, Param 1, ...) notation in expression. New action on Object type / Family - Call function - allowing call only their specific functions (hiding the need to "pick by unique ID" of that specific object type or family).

That would most likely involve:
[*] Creating new set of properties for Object types and Families - Functions
[*] Creating new dialog to create new function - name, parameters, types, descriptions (and some complications such as variadic parameters)
[*] New way to edit functions - outside event sheets - new event sheet per Object type / family, or some way to do in Event sheets without making mess (that includes some more complications, such as Copying / Pasting functions ...)
[*] New actions to call such functions
[*] Optionally - better internal support of calling functions without imposing existing overhead

Edit1: Actually it would be best, if these functions could appear as Actions of that particular Object Type / Family in the list of Actions in Add Action dialog ... (in addition to being called in expressions). Maybe the name "Custom Actions" could be better to disambiguate Function plugin functions and these Object Type / Family functions.
Last edited by CKMartin on Sat Apr 01, 2017 3:49 pm, edited 2 times in total.
B
9
S
3
Posts: 8
Reputation: 668

Post » Fri Mar 31, 2017 4:11 pm

+1 I pretty much always use functions in any project of meaningful complexity and having the editor help with that would be a great feature.
B
10
S
2
Posts: 33
Reputation: 710

Post » Fri Mar 31, 2017 5:26 pm

Great suggestion. I'd love to hear Scirra's opinion on this.
B
135
S
33
G
17
Posts: 1,559
Reputation: 20,732

Post » Fri Mar 31, 2017 5:50 pm

I'd love to see more function support. It is pretty crucial for reusability, scalability, modifiability, etc.
B
45
S
19
G
8
Posts: 514
Reputation: 8,623

Post » Fri Mar 31, 2017 8:12 pm

You should do an example capx showing the overhead.
Image ImageImage
B
171
S
50
G
179
Posts: 8,392
Reputation: 113,478

Post » Fri Mar 31, 2017 9:18 pm

Fair enough @newt, try for yourself (in C3).

http://files.uloziste.com/6468f1d102cb00e7/Funcall%20Measurement.c3p

Edit1: Modified to wait for 5 seconds before measurement starts. If it is not enough, feel free to modify REQUIRED_FRAMES_BELOW_LIMIT to higher value. Or the initial delay for that matter.
Last edited by CKMartin on Fri Mar 31, 2017 9:45 pm, edited 1 time in total.
B
9
S
3
Posts: 8
Reputation: 668

Post » Fri Mar 31, 2017 9:34 pm

Needs a better trigger than fps from the start of layout.
The engine, sputters a bit.
System wait 5 seconds, enable group
Image ImageImage
B
171
S
50
G
179
Posts: 8,392
Reputation: 113,478


Return to General Discussion

Who is online

Users browsing this forum: Hoodloc, Yahoo [Bot] and 1 guest