Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
Working on my game, I made a weapon system (not really the Simple Weapon System that I published here, but it is based on it), and I start to think that the ammount of functions may not be good for its optimization. So, if I have 4 functions (shooting, firerate, pressed buttons, recoil), will it make script so unoptimized that it can start work bad? And will it affect the game performance if I'll use the behavior on 10 weapons (while 2 of them can be used at the same time due to dual wielding)? |
||||
|
By functions if you mean an actual function like var dosomething = function () {..xxx...} then wont be a problem at all...its better to use functions rather than re writing the same code over and over in different places. Behaviours however run every frame and so will use up system resources if you have lots of them - better to create once off Actions instead so that it stops running when not needed. I myself plan to inlcude most of my game code into a single Behavior with parts of it running at different timings (speed) for better performance. In general Actions work great though and best used as much as possible. |
||||
|
Well, then I don't really think that this will cause me the problems, because, by default, only onMouseEvent and onAnimate functions are register on frame (and I'm not even sure about onMouseEvent, because it only responds to mouse keys being pressed). The fire rate and recoil are registered on frame only when shooting is initiated (and unregistered when they done their job). So... Is this fine or it's better to change something? |
||||
|
sounds ok to me...add a 2d overlay with a frame per second counter if you want to confirm no loss of playable frames per second - I always add that in to confirm nothing is causing issues... |
||||
|
Calling a function has a tiny impact because the JS interpreter must put the parameters on a stack, also put the return address on a stack, then branch to the function, and at the end, read the return address from the stack and jump back to the line after the function call. So something like: function min(a,b) { if(a<b) return a; return b; } may be handy, but it also makes execution slower, and if you call this in a loop a thousand times, it may become noticeable. Generally speaking, too many calls, esp. ccb commands such as Linepicks, can slow things down a lot, esp. in the WebGL target, but also on the other platforms, because it will also be interpreted, and not compiled. Always try to keep it simple. |
|