-
10-17-2003, 09:41 PM
#241
Man, you really are one bunch of codef*ckers! But honestly: word up for this topic. I've actually been reading all of the posts up to now and I've really learned a lot. I'm already planning on learning some stuff about ASBroadcaster and FLASM (way to go Squize!) after I finish my current game-engine (two days left and counting....)
I really better get some sleep now
BTW: I'm quite new to the board too (been lurking for over a year but finally decided to actually post something), so err... Hi (too bad I was too late to contribute to the 'sexy'-contest)
signatures after the show, thank you.
-
10-28-2003, 01:00 PM
#242
Here's my tip:
Imagine you have a bullet that is pointing right, but you want to have it point in the direction it is going. If xspeed is positive then the bullet is going right, so its rotation should be 0, else xspeed is negative, so the bullet is going left, and its rotation should be 180.
You could use the following if statements:
Code:
if(this.xspeed>0){
this._rotation=0;
if(this.xspeed<0){
this._rotation=180;
}
but you could make an equation that gives you the correct rotation based on xspeed directly. The following:
Code:
xs=this.xspeed
this._rotation = (((xs/Math.abs(xs))*-180)+180)/2
...would do the same, though it shortens your code, and is, i imagine, faster.
-
10-28-2003, 03:27 PM
#243
Untitled-1.fla
taxman, I think just a normal if-else would be the best solution to achieve what you described, much like your first code:
code:
if (this.xspeed > 0){
this._rotation = 0;
} else {
this._rotation = 180;
}
The second code snippet would alomst certainly be slower. I haven't actually compared them, but I cannot imagine it running faster, because you have a Math.abs() call, 2 divisions etc.
And I think a normal if-else is much more readable, you can instantly see what is happening. Creating very readable code is an important rule in eXtreme Programming (but that's another topic ).
-
10-28-2003, 04:28 PM
#244
I was thinking about that while i was at the dentist earlier... It's true that the best choice would probably be to use:
this._rotation = xspeed<0 ? 180 : 0
I tried to find a way to avoid using Math.abs, but i could only get the same result by using Math.sqrt(xs*xs) :P
About addition/multiplication though, how much performance impact can they have?
In examples with more variables though it really reduces your code. Imagine you had you wanted to check xspeed, yspeed, xcoord, ycoord values you'd need alot more if statements versus a single line.
-
10-28-2003, 04:37 PM
#245
Hype over content...
Although it would reduce your code it would still run slower ( With more variables ), because the flash player would still have to get all those values before performing a single operation on them.
If you seperated up your conditionals ( No "and" or "or" etc. ) and put them in the most likely to run through order then it would be quicker.
Maths functions aren't incredibly bad in the grand scheme of things. You can use little speed-ups such as
var Mabs=Math.abs
or the old classic
a+=2;
instead of
a*=2;
etc.
Squize.
-
10-28-2003, 05:38 PM
#246
Code:
function move(move, xmxm, ymxm, rest, updtx, updty, axis, delay, postprev, oupdt, chFace, chObj, l, r, u, d)
{
();
();
();
_root;
delay;
move;
if (chFace != _root.currentFace)
{
_root.currentFace = chFace;
_level1[chObj + "MC"].gotoAndPlay(chFace);
} // end if
iniT = {r:_level1[chObj].r, s:_level1[chObj].s, t:_level1[chObj].t};
temp = new Object();
temp.r = (iniT.r + Math.floor((iniT.t + 1) / 21)) * d + (iniT.r - Math.floor(Math.abs((iniT.t - 26) / 22))) * u + iniT.r * r + iniT.r * l;
temp.s = iniT.s * d + iniT.s * u + ((iniT.t + 1) % 5 == 0 ? iniT.s + 1 : iniT.s) * r + ((iniT.t + 5) % 5 == 0 ? iniT.s - 1 : iniT.s) * l;
temp.t = (iniT.t - 20 * Math.floor((iniT.t + 1) / 21) + (5 - 5 * Math.floor((iniT.t + 1) / 21))) * d + (iniT.t + 20 * Math.floor(Math.abs((iniT.t - 26) / 22)) - (5 - 5 * Math.floor(Math.abs((iniT.t - 26) / 22)))) * u + ((iniT.t + 1) % 5 == 0 ? iniT.t - 4 : iniT.t + 1) * r + ((iniT.t + 5) % 5 == 0 ? iniT.t + 4 : iniT.t - 1) * l;
chF = _root.calcField(temp);
eval(_level50.walkNova[chF.d.r][chF.d.s][chF.d.t] == "w" && _level50.walkNova[chF.lr.r][chF.lr.s][chF.lr.t] == "w") = _level50.walkNova[chF.ll.r][chF.ll.s][chF.ll.t] == "w";
eval("up" && _level50.walkNova[chF.u.r][chF.u.s][chF.u.t] == "w" && _level50.walkNova[chF.ur.r][chF.ur.s][chF.ur.t] == "w") = _level50.walkNova[chF.ul.r][chF.ul.s][chF.ul.t] == "w";
eval("right" && _level50.walkNova[chF.r.r][chF.r.s][chF.r.t] == "w" && _level50.walkNova[chF.ur.r][chF.ur.s][chF.ur.t] == "w") = _level50.walkNova[chF.lr.r][chF.lr.s][chF.lr.t] == "w";
eval("left" && _level50.walkNova[chF.l.r][chF.l.s][chF.l.t] == "w" && _level50.walkNova[chF.ul.r][chF.ul.s][chF.ul.t] == "w") = _level50.walkNova[chF.ll.r][chF.ll.s][chF.ll.t] == "w";
if (((("down" && down || d == 1) && up || u == 1) && left || l == 1) && right && r == 1)
{
if ((((_level1[chObj + "MC"]._x >= 128 && axis == "x" || move < 0) && _level1[chObj + "MC"]._x >= _root.xSize - 128 && axis == "x" || move < 0) && _level1[chObj + "MC"]._y >= 128 && axis == "y" || move < 0) && _level1[chObj + "MC"]._y >= _root.ySize - 128 && axis == "y" && move < 0)
{
if ((((axis == "x" && _root.xorigin >= _root.xmax - (_root.xres - 1) && move < 0 || _root.xspec < (_root.xmax - (_root.xinit + (_root.xres - 1))) * 5 + 10) && axis == "x" && move < 0 || _root.xspec < 2) && axis == "y" && _root.yorigin >= _root.ymax - (_root.yres - 1) && move < 0 || _root.yspec < (_root.ymax - (_root.yinit + (_root.yres - 1))) * 5 + 10) && axis == "y" && move < 0 && _root.yspec < 2)
{
_level1[chObj].r = temp.r;
_level1[chObj].s = temp.s;
_level1[chObj].t = temp.t;
_level1[axis + "spec"] = _level1[axis + "spec"] + move / Math.abs(move) * -1;
_level1.moveWorld(axis, move);
signal = false;
xtemp = _root.xorigin;
ytemp = _root.yorigin;
for (i = xtemp; i < xtemp + _root.xres; i++)
{
for (j = ytemp - 1; j < ytemp + (_root.yres - 1); j++)
{
_root["s" + (j * 1000 + i)]._y = _root["s" + (j * 1000 + i)]._y + move;
(_root["s" + (j * 1000 + i)]._y + move);
_root["s" + (j * 1000 + i)]._x = _root["s" + (j * 1000 + i)]._x + move;
updty == "" ? _root["s" + (j * 1000 + i)]._x + move : _root["s" + (j * 1000 + i)]._y + move;
tempE = axis == "x" ? i + j * 1000 + delay : j * 1000 + i + delay;
if (_root["s" + (j * 1000 + i)]._x == xmxm || _root["s" + (j * 1000 + i)]._y == ymxm)
{
_root["s" + (j * 1000 + i)]._visible = false;
if (typeof(_root["s" + tempE]) != "movieclip")
{
(_root.olevel);
_root.olevel = _root.olevel++;
_root.createEmptyMovieClip("s" + tempE, _root.olevel);
_root["s" + tempE]._x = -200;
_root["s" + tempE]._y = -200;
_root.level = 0;
_root["intID" + tempE + 100000] = setInterval(_root.pave, 1, delay, i, j, tempE, chFace);
} // end if
_root["s" + (j * 1000 + (i + delay))]._x = updtx;
(updtx);
_root["s" + (j * 1000 + (i + delay))]._x = _root["s" + (j * 1000 + (i + delay + postprev))]._x;
updtx == "" ? _root["s" + (j * 1000 + (i + delay + postprev))]._x : updtx;
_root["s" + (j * 1000 + (i + delay))]._y = updty;
(updty);
_root["s" + (j * 1000 + (i + delay))]._y = _root["s" + (j * 1000 + (i + delay + postprev))]._y;
updty == "" ? _root["s" + (j * 1000 + (i + delay + postprev))]._y : updty;
_root["s" + (j * 1000 + (i + delay))]._visible = true;
signal = true;
} // end if
} // end of for
} // end of for
if (signal)
{
signal = false;
_root[axis + "origin"] = _root[axis + "origin"] + oupdt;
} // end if
} // end if
}
else
{
_level1[chObj].r = temp.r;
_level1[chObj].s = temp.s;
_level1[chObj].t = temp.t;
_level1[chObj + "MC"]._y = _level1[chObj + "MC"]._y - move;
(_level1[chObj + "MC"]._y - move);
_level1[chObj + "MC"]._x = _level1[chObj + "MC"]._x - move;
axis == "x" ? _level1[chObj + "MC"]._x - move : _level1[chObj + "MC"]._y - move;
} // end if
} // end if
();
();
();
}
I thought shorter was faster. At least i don't have to bother about people stealing my code. :P
-
10-28-2003, 06:09 PM
#247
-
10-28-2003, 06:15 PM
#248
That's the decompiler's version of the code.
-
10-28-2003, 08:47 PM
#249
ah, stupid compiler, the programmer should be ashamed of himself
~yarr
-
10-29-2003, 11:15 AM
#250
Indeed...
But we're going off topic, this thread is meant to discuss the word "sexy" and such.
-
11-03-2003, 02:23 AM
#251
memory optimizing ? how ?
've read some of the post.
i'm makin some clone of FF 5 for an RPG battle, though not completed yet.
i use some loop & goto and play ( as usual).
the battle run normally at first but become SLOWWWWWWWWW after bout 3 minutes. using the task manager, i found that the memory usage is climbing as time goes by ^^.
even after the battle finished, though the memory usage not climb anymore, it steady as same as when the battle finished.
if I entered the battle the memory started to climb again .
is there any way to utilize the memory ???
though it not finished, the source is as big as 5MB and the swf is 2.5MB.
please help me ( tasukette kudasai(jpn))
-
11-03-2003, 08:14 AM
#252
Hype over content...
2.5 meg swf ? Mate that's bigger than all my games added together
Although not really an optimising question, check this link out: http://www.flashkit.com/board/showth...hreadid=504216
Squize.
-
11-11-2003, 04:56 AM
#253
im at school so i dont have time to read through the whole thing, but is it true that case is faster than if? and is the
_root.mc.mc.gotoAndPlay(3);
faster than
tellTarget(_root.mc.mc){
gotoAndPlay(3);
}
-
11-11-2003, 01:21 PM
#254
Originally posted by Squize
or the old classic
a+=2;
instead of
a*=2;
Lol, is it just me, or do you think squize had something else ( most probably dirty ) on his mind when typing that one out?
i guess you mean a ^= 2; But i'm not that hot with bitwise stuff.
But great link, jobemjobem explains it really well, but can be summarised thus: always use var!
Ihoss:
The old flash 4 syntax ( telltargets etc ) are apparently faster than any of the "new" dot-syntax code. If-versus-switch - i think they came out equal. Not 100% though.
-
11-11-2003, 02:09 PM
#255
Hype over content...
I meant a+=a;
When I post something stupid, I like to make it really stupid
I'm just glad no one brought any attention to it
Switch & If worked out the same ( Strille did a little test a couple of pages back ), and nasty ol' 4 syntax is still quicker under mx ( Even under the 7 player I believe ).
Squize.
-
11-11-2003, 06:03 PM
#256
Heli Attack!
I did a little test the other day, forgot to post it.
If your into making tilebased games (like me =)
Then you know you floor alot of values.
We already know that to save from doing Math.floor all the time at the start to do something like
floor = Math.floor, and then you dont have to do the Math lookup. But funilly enough, the Flash 4 version of the command int(); is faster, by almost double, even when compared against the direct referenced function..
So use int(); eg: map[int(x/tw)][int(y/th)];
-
11-11-2003, 07:40 PM
#257
Hype over content...
...and that's one of the many reasons I love you.
Thanks for sharing that little gem babe.
Squize.
-
11-12-2003, 06:47 AM
#258
-
11-19-2003, 04:08 PM
#259
Senior Member
I haven't had time yet to read over this whole really good thread... but I was wondering if it is quicker to check for four different things, that have the same result using one if statement and using OR, or is it better to use four different ifs statement?
code: if(_root.bullet._x<-15|_root.bullet._x>600|_root.bullet._y<-15|_root.bullet._y>415){removeMovieClip(bullet) }
OR
if(_root.bullet._x<-15){removeMovieClip(bullet)}
if(_root.bullet._x>600){removeMovieClip(bullet)}
if(_root.bullet._y<-15){removeMovieClip(bullet)}
if(_root.bullet._y>415){removeMovieClip(bullet)}
Thanks
-
11-19-2003, 04:12 PM
#260
Heli Attack!
If you nest them, they are faster
if(_root.bullet._x<-15){
if(_root.bullet._x>600){
if(_root.bullet._y<-15){
if(_root.bullet._y>415){
removeMovieClip(bullet);
}
}
}
}
But its much more annoying to code with the If statements expanded.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|