A Flash Developer Resource Site

Page 11 of 21 FirstFirst ... 789101112131415 ... LastLast
Results 201 to 220 of 411

Thread: Optimization Tips

  1. #201
    Senior Member random10122's Avatar
    Join Date
    Mar 2002
    Location
    Sheffield, UK
    Posts
    1,747
    Ahhh... right, sorry. So this only offers a performance increase if the state of a key has to be checked more than once in a frame.

    Gotya.

    fracture2 - the sequel
    fracture - retro shooter
    blog - games, design and the rest

    "2D is a format, not a limitation" -Luis Barriga

  2. #202
    Member
    Join Date
    Oct 2002
    Posts
    58

    Bullet MC hitting more than 1 MC

    I'm not sure if this has already been explained in thread but if it has, I don't think I got it, plz try help.

    If I have a bullet MC, I need to store the hitTest action in it for when it hits people MC's.

    say the people MC's are named:

    man1
    man2
    man3

    etc...

    man29
    man30

    Well instead of 30 If hitTest actions can't I simply have one which will be triggered if the bullet hits any of them?

    Plz try explain this as best you can.

    Thanks for your help.

  3. #203
    Senior Member random10122's Avatar
    Join Date
    Mar 2002
    Location
    Sheffield, UK
    Posts
    1,747
    ripX tells me that multi-dimensional arrays are slower than just the one dimension... But, is a 3D array slower than a 2D and faster than a 4D?

    fracture2 - the sequel
    fracture - retro shooter
    blog - games, design and the rest

    "2D is a format, not a limitation" -Luis Barriga

  4. #204
    Heli Attack! iopred's Avatar
    Join Date
    Jun 2003
    Location
    Sydney, Australia
    Posts
    923
    of course, because you have to look up the first dimension, then the second, then the third..

    However I would say the speed loss is negligable..

    Also here is a little speed boost I have got..

    lets say we have a 2d array which is rather wide:


    map = Array100x100();
    for(var y = 0; y < 100 ;y++){
    var dmap = map[y];
    for(var x = 0; x < 100 ; x++){
    trace(dmap[x]);
    }
    }

    Bit faster. Would cut off the difference between dimensions IMHO.

  5. #205
    Senior Member random10122's Avatar
    Join Date
    Mar 2002
    Location
    Sheffield, UK
    Posts
    1,747
    cheers preddy.

    fracture2 - the sequel
    fracture - retro shooter
    blog - games, design and the rest

    "2D is a format, not a limitation" -Luis Barriga

  6. #206
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    Drunken post, which I really shouldn't do in this thread...

    If you look at multi dim arrays in byte code it's frightening how much data has to be pulled up before actually getting the value you want.

    Where poss. you should try and pre-calc the multi-dim values you want ( ie 99 times out of a 100 it's going to be map data ) and transfer it to a single dim array.

    Squize.

    PS. As ever, sexy code pred. Just once post something lame

  7. #207
    Senior Member fantasio's Avatar
    Join Date
    May 2000
    Location
    at the progress bar
    Posts
    409

    what a great thread!

    hello everyone,
    i just lurked so far and read all of those nice tips, some of which I already knew, some new ones.

    Now, a question:
    does it make sense to incorporate all those tips in my current project with flash 2004 around the corner and with that possible performance increases ???

    In my last projects I tried to go further down the road of OOP vs. my so far chaotic, but effective scripting.

    Now a lot of performance issues are due this style of scripting.
    For example the "dot" syntax is very cool to work with but a lot of times, the tell target is much faster.
    But I think it's a pain in the butt to use so many different approaches to coding all the time....

    Whaddaya think, is MM getting their act together or do I have to re-code every given project after i finished it, to make it perform better (very time consuming that...).

    Also, maybe we should collect all known and working optimisations in a FAQ ?

  8. #208
    Senior Member
    Join Date
    Jun 2002
    Location
    Manchester, UK
    Posts
    2,357
    With regard to multi-dimentional arrays being slow, I quickly wrote this which I was talking about to Random.

    Code:
    var mapL = 3;
    var mapH = 3;
    var l = 0;
    map = [1, 2, 1, 2, 1, 2, 1, 2, 1];
    for (var i = 0; i<mapL; i++) {
    	for (var j = 0; j<mapH; j++) {
    		t = attachMovie("tile", "tile"+i+"_"+j, d++);
    		t._x = i*32;
    		t._y = j*32;
    		t.gotoAndStop(map[l]);
    		l++;
    	}
    }
    With a map editor this information can be produced easily and keep the array fast and 1 dimentional.

    RipX

  9. #209
    Untitled-1.fla strille's Avatar
    Join Date
    Mar 2001
    Location
    Sweden
    Posts
    1,626
    Yes, 1 dimensional arrays are generally a bit faster. Since you have the map in one array, you can loop through it using only one loop:
    code:
    var mapL = 3;
    map = [1, 2, 1, 2, 1, 2, 1, 2, 1];

    for (var i = 0; i<map.length; i++) {
    t = attachMovie("tile", "tile"+i, i);
    t._x = (i % mapL) * 32;
    t._y = int(i/mapL) * 32;
    t.gotoAndStop(map[i]);
    }


    The advantage is that you can remove the variables l and d and use i instead. And you remove one nested for loop, which is good. You have to do some more calculations to place the tile, but the overall code runs a bit faster than the code RipX posted above.

  10. #210
    Senior Member
    Join Date
    Jun 2002
    Location
    Manchester, UK
    Posts
    2,357
    I'd actually thought of that way but I didn't want to complicate things too much since I wanted to show just the one optimation! But nice one Strille for posting that

    RipX

  11. #211
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    fantasio good question.

    I'm still of the mindset that if a game works, then don't kill yourself trying to optimise it.

    Use tellTarget and other straight forward optimisations where poss. but I've not sat in front of a routine for a while and tried to skim a few ms off the execution time.
    I find having a think about the best way to actually write a routine before hand is a million times easier than writing something and then trying to optimise it. May be a really blatant statement, but it's something I've never really worried about too much before 'cause I always had the time to optimise things, but things have changed recently ( I've got into the habit of using quite long var names, which is a speed no-no, but it saves me so much time when it comes to debugging that I can cope with losing the odd ms ).
    If I do actually optimise something then it'll be the always called inner loops.

    As to the faq, mBenney is working on one atm ( I've stupidly said I'd do the OOP section ).

    Going back to the 1 dim arrays for maps, how do you guys plan to include the attributes ? Skip every other byte or have a seperate attribute array ?
    To be honest I think it'll be easier to just pre-calculate the current map data you need and store that in a temp. 1 dim array ( Using it in effect like a stack ).

    Squize.

  12. #212
    Heli Attack! iopred's Avatar
    Join Date
    Jun 2003
    Location
    Sydney, Australia
    Posts
    923
    Hey guys,

    Just doing some testing...

    Code:
    timer = getTimer();
    var temp = 0;
    for (var i = 0; i<100000; i++) {
    	if(i && i && i){
    		temp++;
    	}
    }
    timer = getTimer()-timer;
    A simple if statement, seeing if i is not 0, 3 times. This runs at about 5600ms in Flash's inbuilt player.

    Code:
    timer = getTimer();
    var temp = 0;
    for (var i = 0; i<100000; i++) {
    	if(i){
    		if(i){
    			if(i){
    				temp++;
    			}
    		}
    	}
    }
    timer = getTimer()-timer;
    The EXACT same code, but with the if's expanded results in a cost of 4800ms.. Thats a fair bit!

    My conclusion, Flash's compiler stinks so hard, I want to puke.
    Last edited by iopred; 08-29-2003 at 01:28 AM.

  13. #213
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    is that with the "Omit trace actions" set or clear in the publish settings?
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  14. #214
    Heli Attack! iopred's Avatar
    Join Date
    Jun 2003
    Location
    Sydney, Australia
    Posts
    923
    Urg, kill me.. Didnt have it checked =|

  15. #215
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    Still it's important to have it checked. i, for one, never bothered with it but you can bet anything i make now will have it checked.
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  16. #216
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    It's always quicker to split your If statements up ( And avoid and,or ) because Flash has to get all the data needed for ALL the checks before it can perform even the first one, so with an if statement with 3 conditionals to check, even if the first one fails to meet your condition it's still got another 2 lots of data first ( And if you throw some array[offset] checks into that as well it's a stupid amount of code generated ).

    As a follow up question, I've seen a lot of people use the switch statement a lot recently, although there's not meant to be any performance improvement from it. Anyone know for sure ? Cheers

    Squize.

  17. #217
    Untitled-1.fla strille's Avatar
    Join Date
    Mar 2001
    Location
    Sweden
    Posts
    1,626
    Squize, I made a comparison between if-else and switch, and it appear that they are in fact equally fast (or slow, this is Flash we're talking about )

    This is a bit surprising, one would think that switch would be faster since you evaluate the value once and then jump to the right code, while if-else has to evaluate each if-statement until one is true or there are no more. Could it be that the switch-statement is compiled as a series of if-else statements?

    Anyway, here's the code I used:

    code:
    a = 4;

    time = getTimer();
    for (var n=0;n<10000;n++) {
    if (a == 1) {
    b = a;
    } else if (a == 2) {
    b = a;
    } else if (a == 3) {
    b = a;
    } else if (a == 4) {
    b = a;
    }
    }
    trace("if-else: "+(getTimer()-time));

    time = getTimer();
    for (var n=0;n<10000;n++) {
    switch(a) {
    case 1:
    b = a;
    break;
    case 2:
    b = a;
    break;
    case 3:
    b = a;
    break;
    case 4:
    b = a;
    break;
    }
    }
    trace("switch: "+(getTimer()-time));



    In either case, I think switch looks better...

  18. #218
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    Thanks mate!

    You're just a sexy actionscript writing machine atm

    Squize.

  19. #219
    Senior Member random10122's Avatar
    Join Date
    Mar 2002
    Location
    Sheffield, UK
    Posts
    1,747
    Just thought i would drop a note to say that i have collected the most usefull tips from this thread in a page on my webspace as a list split into three sections: graphics/code/misc

    Just thought i would make it easier to search through. (Link in sig)

    fracture2 - the sequel
    fracture - retro shooter
    blog - games, design and the rest

    "2D is a format, not a limitation" -Luis Barriga

  20. #220
    Untitled-1.fla strille's Avatar
    Join Date
    Mar 2001
    Location
    Sweden
    Posts
    1,626
    random10122, that's a very good idea. Reading through this whole thread can probably be a bit dry...

    Squize, I'm trying my best to be as sexy as humanly possible.

    Btw Squize, I'm naming you the current champion of the use of the word "sexy" in your posts:

    Squize: 16 (887 posts)
    BlinkOk: 5 (2785 posts)
    Strille: 2 (620 posts)
    I_am_TheFlasher: 1 (400 posts)
    nGFX: 1 (159 posts)
    Saphua: 1 (381 posts)
    Tonypa: 1 (2425 posts)
    marmotte: 0 (1562 posts)
    iopred: 0 (64 posts)

    If someone can find a Games member with a higher count before this post was posted, let me know

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center