3D Rad - Free 3D game maker - Forum

This forum is now archived!

This forum is locked, and is a read-only version. A new community-ran forum can be found at classdev.net

News:

The 3DRad community can be found at classdev.net.

Pages: [1]

Author Topic: can this for loop made smaller,quiker or more eficient  (Read 204 times)

« on: February 02, 2014, 06:38:18 AM »
i got the collision to work eventually but am not sure if this best and fastest way to loop it as i have to make so each card canot be cheked against itself or all cards will be hidden so card 0 canot be checked against when check the array loop of i hence the continue part of each line check so can tell me if this is the most eficient way i have already done

this is the part of code loop:

thank all

//-----------------------------------------------------------------------------------------------
void cardcoll()
{
int i;
for(i=0;i<Imposters;i++){
if( i == 0 ) continue;if(iVectorLength(CardLocation[0]-CardLocation)<10){HideCard(i);}
if( i == 1 ) continue;if(iVectorLength(CardLocation[1]-CardLocation)<10){HideCard(i);}
if( i == 2 ) continue;if(iVectorLength(CardLocation[2]-CardLocation)<10){HideCard(i);}
if( i == 3 ) continue;if(iVectorLength(CardLocation[3]-CardLocation)<10){HideCard(i);}
if( i == 4 ) continue;if(iVectorLength(CardLocation[4]-CardLocation)<10){HideCard(i);}
if( i == 5 ) continue;if(iVectorLength(CardLocation[5]-CardLocation)<10){HideCard(i);}
if( i == 6 ) continue;if(iVectorLength(CardLocation[6]-CardLocation)<10){HideCard(i);}
if( i == 7 ) continue;if(iVectorLength(CardLocation[7]-CardLocation)<10){HideCard(i);}
if( i == 8 ) continue;if(iVectorLength(CardLocation[8]-CardLocation)<10){HideCard(i);}
if( i == 9 ) continue;if(iVectorLength(CardLocation[9]-CardLocation)<10){HideCard(i);}
if( i == 10 ) continue;if(iVectorLength(CardLocation[10]-CardLocation)<10){HideCard(i);}
if( i == 11 ) continue;if(iVectorLength(CardLocation[11]-CardLocation)<10){HideCard(i);}
if( i == 12 ) continue;if(iVectorLength(CardLocation[12]-CardLocation)<10){HideCard(i);}
if( i == 13 ) continue;if(iVectorLength(CardLocation[13]-CardLocation)<10){HideCard(i);}
if( i == 14 ) continue;if(iVectorLength(CardLocation[14]-CardLocation)<10){HideCard(i);}
if( i == 15 ) continue;if(iVectorLength(CardLocation[15]-CardLocation)<10){HideCard(i);}
if( i == 16 ) continue;if(iVectorLength(CardLocation[16]-CardLocation)<10){HideCard(i);}
if( i == 17 ) continue;if(iVectorLength(CardLocation[17]-CardLocation)<10){HideCard(i);}
if( i == 18 ) continue;if(iVectorLength(CardLocation[18]-CardLocation)<10){HideCard(i);}
if( i == 19 ) continue;if(iVectorLength(CardLocation[19]-CardLocation)<10){HideCard(i);}
if( i == 20 ) continue;if(iVectorLength(CardLocation[20]-CardLocation)<10){HideCard(i);}
if( i == 21 ) continue;if(iVectorLength(CardLocation[21]-CardLocation)<10){HideCard(i);}
if( i == 22 ) continue;if(iVectorLength(CardLocation[22]-CardLocation)<10){HideCard(i);}
if( i == 23 ) continue;if(iVectorLength(CardLocation[23]-CardLocation)<10){HideCard(i);}
if( i == 24 ) continue;if(iVectorLength(CardLocation[24]-CardLocation)<10){HideCard(i);}
if( i == 25 ) continue;if(iVectorLength(CardLocation[25]-CardLocation)<10){HideCard(i);}
if( i == 26 ) continue;if(iVectorLength(CardLocation[26]-CardLocation)<10){HideCard(i);}
if( i == 27 ) continue;if(iVectorLength(CardLocation[27]-CardLocation)<10){HideCard(i);}
if( i == 28 ) continue;if(iVectorLength(CardLocation[28]-CardLocation)<10){HideCard(i);}
if( i == 29 ) continue;if(iVectorLength(CardLocation[29]-CardLocation)<10){HideCard(i);}
if( i == 30 ) continue;if(iVectorLength(CardLocation[30]-CardLocation)<10){HideCard(i);}
if( i == 31 ) continue;if(iVectorLength(CardLocation[31]-CardLocation)<10){HideCard(i);}
if( i == 32 ) continue;if(iVectorLength(CardLocation[32]-CardLocation)<10){HideCard(i);}
if( i == 33 ) continue;if(iVectorLength(CardLocation[33]-CardLocation)<10){HideCard(i);}
if( i == 34 ) continue;if(iVectorLength(CardLocation[34]-CardLocation)<10){HideCard(i);}
if( i == 35 ) continue;if(iVectorLength(CardLocation[35]-CardLocation)<10){HideCard(i);}
if( i == 36 ) continue;if(iVectorLength(CardLocation[36]-CardLocation)<10){HideCard(i);}
if( i == 37 ) continue;if(iVectorLength(CardLocation[37]-CardLocation)<10){HideCard(i);}
if( i == 38 ) continue;if(iVectorLength(CardLocation[38]-CardLocation)<10){HideCard(i);}
if( i == 39 ) continue;if(iVectorLength(CardLocation[39]-CardLocation)<10){HideCard(i);}
if( i == 40 ) continue;if(iVectorLength(CardLocation[40]-CardLocation)<10){HideCard(i);}
if( i == 41 ) continue;if(iVectorLength(CardLocation[41]-CardLocation)<10){HideCard(i);}
if( i == 42 ) continue;if(iVectorLength(CardLocation[42]-CardLocation)<10){HideCard(i);}
if( i == 43 ) continue;if(iVectorLength(CardLocation[43]-CardLocation)<10){HideCard(i);}
if( i == 44 ) continue;if(iVectorLength(CardLocation[44]-CardLocation)<10){HideCard(i);}
if( i == 45 ) continue;if(iVectorLength(CardLocation[45]-CardLocation)<10){HideCard(i);}
if( i == 46 ) continue;if(iVectorLength(CardLocation[46]-CardLocation)<10){HideCard(i);}
if( i == 47 ) continue;if(iVectorLength(CardLocation[47]-CardLocation)<10){HideCard(i);}
if( i == 48 ) continue;if(iVectorLength(CardLocation[48]-CardLocation)<10){HideCard(i);}
if( i == 49 ) continue;if(iVectorLength(CardLocation[49]-CardLocation)<10){HideCard(i);}
if( i == 50 ) continue;if(iVectorLength(CardLocation[50]-CardLocation)<10){HideCard(i);}
if( i == 51 ) continue;if(iVectorLength(CardLocation[51]-CardLocation)<10){HideCard(i);}
if( i == 52 ) continue;if(iVectorLength(CardLocation[52]-CardLocation)<10){HideCard(i);}
}
}
« Reply #1 on: February 03, 2014, 05:28:02 AM »
Could you try to explain what you're trying to achieve? I can't make much of this...

Why would this:
for (int i=0; i<imposters; i++)
{
if (iVectorLength(CardLocation-CardLocation)<10) HideCard(i);
}
...Not suffice?

Just a little note, the brackets are not necessary when you have merely one action after a statement.
Rocket Rumble, a 3D Rad puzzle game:
http://www.3drad.com/forum/index.php?topic=9896.0
« Reply #2 on: February 03, 2014, 05:58:07 AM »
Hi i am making a card game of 52 cards, made from skinmesh imposter i need to detect when a card is ontop of another card, when one card is within threshold of other card they will bothe be removed/hidden, the problem is i need to check all 52 cards against eachothers position an hide two cards if they are within the threshold, the problem is i had to make the long code so that say card 1 is not checked against itself in the loop as then it will hide itself even when another card is not near it, the loop works but does lag a bit soi wondered if it could be made more eficient but still not check the cards agaist itself as it will be hiden straight away, so say when i check the vectorlength of card 1 agaist the array of all cards it checks card 0 and then cards 2 to 52 and not card 1 as it will hide itself, so what happens is when it checks cardlocation against cardlocation it will check card 0 against all cartds including card 0 and 1 against 1 etc then it hides the card when it checks against itself.

hope this explains as i had help with translation as english not first language
« Reply #3 on: February 03, 2014, 08:13:38 AM »
just noticed in my code post there should be after the second cardlocation so all lines would be iVectorLength(CardLocation[0]-CardLocation)<10){HideCard(i);}    dont know how they got removed when i pasted the code so now you can see the problem properly when i check the cardlocation 0 against cardlocation i it reads 0 against 0 and hides the card when no card is near it
« Reply #4 on: February 03, 2014, 06:57:19 PM »
If your really picky and want the absolute fastest code, go with 20 lines and ugly  large looking scripts.

If you don't mind loosing a few milliseconds here or there and want neat and tidy looking code, use loops.

The real answer here can only be supplied Fernando because he has access to 3drads internals, and would know more on what exact process is going on and which would be the fastest.

Generally, my conclusion above i believe is the proper answer for scripting in general.

Read on for my explanation of my above view.



i know what your asking, i wondered years ago about this too.

My 3 cents worth. :)

When you do looping, your repeating the same piece of code, lets say, 20 times.

if you instead print out that code as individual statement lines, you would have 20 lines of script, instead of a loop with maybe 2 to 5 lines.

Technically, i believe 20 lines would be more efficient, simply because, looping adds a few more lines to the process, plus 1 or 2 variables as well.

So... the straight 20 lines of code is still processed 20 times by both process's.

The looping is probably a few milliseconds slower due to the extra loop code processed 20 times too.

But the loop also looks much neater and makes your script easier over all to work with.
« Reply #5 on: February 04, 2014, 06:42:15 AM »
i think you are right, long code sections look like they will take longer to execute but in a loop they seem to run slower, the main problem here with the ivectorlength check is i found is if i do it in a loop it checks card
  • against all card positions in so ends up checking card
    • against itself and and it registers the distance as below threshold it will delete card
    • so i have to put the first part in each line to stop it checking against its own position i have tried several ways of for loop even stacking and this seems the only way i have found to get the job done so i think it must be the most eficient way even though it looks messy.

    if anyone does have the solution to stop self checking in a short loop id love to test it

     
« Reply #6 on: February 04, 2014, 09:54:30 AM »
it seems like you've got the logic down pat,  so there's really no decision to be made here... use the method Roberto suggested... (with a slight modification, because i never saw where the location variables are set)...

Code: [Select]
for (int i=0; i<imposters; i++)
{
   iObjectImposterGet(OBJ_X,intImposterNum,QuaternionVar,Vector3Var);
   if (iVectorLength(CardLocation[i]-refCardLocation)<10) HideCard(i);
}

(assumes HideCard() is a function)


you're not writing assembler code... you don't need the longwinded version :)

--Mike
« Reply #7 on: February 05, 2014, 06:50:48 AM »
can anyone tell me a shorter way of stopping ivectorlength checking an object against itself as in say i have 20 object in an array and want to check distance using ivectorlength using ivectorlength(position[0]-position as when it checks against the array it will come up against istelf as in object
  • and detects it as under the threshold which is the problem i am having so any ideas

thanks
Pages: [1]