Page 3 of 4

Re: Ideas for Optimization

PostPosted: Tue Sep 15, 2009 5:44 pm
by Hblade
For mobile devices, turn on Motion compensation.

Re: Ideas for Optimization

PostPosted: Tue Sep 15, 2009 7:40 pm
by Fuzzy
Bee-Ant wrote:Thats why i said it needs a deep thinking. For starting,using basic code is okay i think. Then when the project is nearly finished,just edit code to that simpler one. :D
Just my opinion :P



I did the deep thinking for you. The code is easy, always the same, just change the values.

I will rephrase your statement so you can see its silly.

"Then when the math test is nearly finished, just edit the answers to that simpler formula."

You see? Do simple and clean work, right at the beginning.

Code: Select all
int constrain(int smallest, int largest, int value)
{
    return max(smallest, min(value, largest));
}


There. Now its a GE function for global.

use it...

Code: Select all
x = constrain(left, right, x);

Re: Ideas for Optimization

PostPosted: Tue Sep 15, 2009 8:40 pm
by Bee-Ant
Ahhh...you're right :P
Okay,you mind to deep think for me right?thanks :D

I will give my way to maximise performance: turn off activation out of vision. And avoid mega cloning usage (clone more than 500)
Use narrower view,use multifunction actor,avoid too much of collision usage,and use midi for the music :P

Re: Ideas for Optimization

PostPosted: Tue Sep 29, 2009 11:05 am
by Kalladdolf
Keep view movement to the minimum -- don't make the player its parent (!).

Re: Ideas for Optimization - Windows Mobile

PostPosted: Fri Dec 04, 2009 3:37 am
by DST
If shots or enemies have an explosion or similiar animation when they die, don't put it in the destroyactor code if they can be destroyed by going offscreen. Put it in the collision script instead.

Put the health<0 death check in the collision too, not draw actor.

Transfer to local variables when possible. Enemy>create Actor>

health=enemyStats[type][0];

Then use health for the rest of the enemies code.

Construct variables before acting on them, rather than repeating an operation in the code itself;
int xx=x+10;
int yy=y+20;
if(something something something xx yy).
if(something something else xx yy)


Use modulo when assigning 1d screen array values:
Code: Select all
int horiz;
int vertic;
for(i=0; i<300; i++){
horiz=i%20;  //find horizontal cell
vertic=(i-horiz)/20;    //find vertical cell
horiz*=32;   //multiply by cell width
vertic*=32;
CreateActor("jewel", "redjewel", "", "", horiz, vertic, true);
}

Re: Ideas for Optimization - Windows Mobile

PostPosted: Sat Dec 05, 2009 2:09 am
by Hblade
You can try using small images, (Nes or SNES resolution sprites) and scaling them with a canvas :D

Re: Ideas for Optimization - Windows Mobile

PostPosted: Sun Dec 06, 2009 10:42 am
by Bee-Ant
Hblade wrote:You can try using small images, (Nes or SNES resolution sprites) and scaling them with a canvas :D

But be carefull, scaling them would need draw actor

Re: Ideas for Optimization - Windows Mobile

PostPosted: Sun Dec 06, 2009 5:52 pm
by Hblade
Yeah, I found out while making something once that if you use a for statement inside of another for statement, it lags but if you separate them it runs smooth :D

Re: Ideas for Optimization - Windows Mobile

PostPosted: Sun Dec 06, 2009 7:36 pm
by Bee-Ant
Thats right, moreover if more than 2 nested FOR. It will lag the game.
The best time to use the nested FOR is when once the game started up.

Re: Ideas for Optimization - Windows Mobile

PostPosted: Sun Dec 06, 2009 7:38 pm
by Hblade
The for statement is very powerfull :3 It updates everything in it in 2 frame. Check out the HP bar to see what I mean if you want to :D

Re: Ideas for Optimization - Windows Mobile

PostPosted: Mon Dec 07, 2009 3:03 am
by Bee-Ant
Hblade wrote:The for statement is very powerfull :3 It updates everything in it in 2 frame. Check out the HP bar to see what I mean if you want to :D

Unfortunatelly, im lazy to search something...would you mind to post the link anytime you wanna show something ?

Re: Ideas for Optimization - Windows Mobile

PostPosted: Mon Dec 07, 2009 12:59 pm
by Hblade
I ment 1 frame... Anyways, the for statement...

Example, say you have a canvas and you want to draw 4 lines in it
Instead of the basic moveto lineto stuff, put it in a for statement.
Here's an example
Code: Select all
for (i=0; i<4; i++)
{
         setpen(color, transp, size);
         moveto(0, i);
         lineto(width-1, i);
         i+=4;
}

What that code will do is make 4 lines seperatly inside of a canvas
But it's different then making multiple moveto's and linetos because of you used multiple movetos and linetos, you would see the lines being... drawn so to say, 1 line every frame. But the for statement makes everything inside of it happen all at once :D

Re: Ideas for Optimization - Windows Mobile

PostPosted: Wed Jan 06, 2010 5:15 pm
by Superbeni
I know, this topic is quite old, but I have a question to optimization:
I made an 2D shooter like Space Invaders, what can I use instead of collision? (between the shot and the enemy)
If i make an activation region, I have to move the view to the enemys (instead of moving all enemys), or is there a better way?

I reduced the collisions and draw actor events, but it still runs very slow on my Smartphone.

PostPosted: Thu Jan 07, 2010 4:41 pm
by Fuzzy
The biggest problem with a collision formula is that it uses a square root which is very costly for the CPU to calculate. In your case your best bet would be to reduce the number of collision checks to make, and/or to use a simpler formula.

Start by spacing your aliens so that the shot can only touch one row at a time. You might have to adjust your shot size too depending on the look of the spacings. So if your shot is 4 pixels tall, make sure there are five(or more) pixels between rows of aliens.

Now you can use a wireframe actor around each row and just check that. If you have a collision with that, you then check for collisions against each alien in that row. You will likely want to do that in script with the distance function. If you have a lot of aliens in a row you can either nest wire frame actors inside other wireframes, using the outside wireframe to turn on collisions for the inside wireframes. Its almost like stacking blocks, and this is called hill climbing, if that makes sense.Dont forget to turn those collisions back off when the shot exits the outer most wireframe.

Next, you could have less actors. Let one actor represent several aliens(maybe 4?) With some trickery(special animations) and distance checks you can make specific aliens die.

Here is a non square root distance function. You can place this in global code.
Code: Select all
int QDist(int shotX, int shotY, int targetX, int targetY) // quick and dirty distance
{
    return (abs(shotX - targetX) + abs(shotY - targetY));
}


This will return a distance that is the sum of the x and y distances. It can have false results, so you want to make sure that you are already close (probably with a wireframe). Only use this function if you know the shot is in a specific area.

I've been up all night and I am too tired to error check this... Sorry for any mistakes.

Re: Ideas for Optimization - Windows Mobile

PostPosted: Thu Jan 07, 2010 4:55 pm
by Superbeni
Its without rows, more like random spawning, but also without random and spawning. :lol:
But i could reduce the collsions an changed/reduced the draw actor scripts, and now it runs quite smoothly.