Why are Plugins Faster then Construct2 ?

Discussion and feedback on Construct 2

Post » Fri Oct 26, 2012 8:49 am

For example at Pathfinding or creating random generated terrain.

Why is it that these things are best done with plugins that use straight up Javascript instead of using Construct2 directly?

Is Construct2 not converted into JavaScript? So what are the reasons that it is slower?
B
40
S
11
G
4
Posts: 665
Reputation: 8,403

Post » Fri Oct 26, 2012 9:23 am

@Schoening : I suppose that when you say "Why is it that these things are best done with plugins that use straight up Javascript instead of using Construct2 directly?", you mean for example doing the Pathfinding with events inside C2.
As a plugin maker, I can explain some reasons, perhaps @Ashley is going to add a few things.
- C2 is in fact a big game framework, and leike every game framework, you have a main gameLoop(), which contains the various events, and that one is run at each step, 60 times per seconds (in C2, those are the events listed inside the editor, that you add with the mouse).
- when you use events, you need to conform to C2's mode of working, which is event-based (a paradigm of programming, you can also see reactive programming in the litterature).
- some algorithm are easier dealt with a functionnal or modal way of developping (something you can do with Javascript, C/C++, Java, etc...)
- Ashley has baked a lot of checks, memory reuse, smart tricks and the like inside C2's engine. That means that every event you add inside the loop in the editor is going to be efficient regarding the use of graphics, sounds, browser access, memory, etc... However, in a plugin, you often deal with pure mathematic problem (like crawling a graph => pathfinding, face recognition => decisions trees, etc...). Those "mathematical" problems doesn't need all teh tools and gear needed for media handling that C2 provide, but they pass them anyway if you use events.
- So if you have a JS plugin, you can defer small specialized work to a small JS function, that bypass C2 workline, or in some case (webworkers and all that) can execute parallel to C2's main thread.

TL;DR : C2 handle all the gamefield that you can leverage in a JS plugin where you concentrate on only a small problem, helping you being faster in that particular case.
B
33
S
9
G
6
Posts: 709
Reputation: 6,704

Post » Fri Oct 26, 2012 9:30 am

@Pode
Thank you for the quick reply :)
I was thinking along those lines too.
Construct2 has to take far more things into account and thus the exported code is probably a lot more complex then my own simple JavaScript code would be.

B
40
S
11
G
4
Posts: 665
Reputation: 8,403


Return to Construct 2 General

Who is online

Users browsing this forum: rekjl, saiyadjin and 13 guests