The Daily Click ::. Forums ::. Klik Coding Help ::. 3D array fastloop
 

Post Reply  Post Oekaki 
 

Posted By Message

Rob Westbrook



Registered
  25/05/2007
Points
  193

360 OwnerVIP Member
26th June, 2012 at 26/06/2012 14:29:22 -

Hey Guys. I found a while ago a thread where someone gave the formula for looping through a 3D Array with a single fastloop. Kinda like the loopindex("loop") mod array width for X and loopindex("loop") / array width for Y with 2D arrays, but with a Z dimension as well. The good old recursive fastloops is just too slow for my levels.

I can't for the life of me remember where it was though. Anyone know the formula and would care to share?

Cheers!

 
There are 10 types of people in the world: Those who understand binary and those who don't.

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
26th June, 2012 at 26/06/2012 15:21:12 -

+ Whenever...
-> Start fastloop "Load Array", DimX( "Array" ) * DimY( "Array" ) * DimZ( "Array" ) times

+ On Loop "Load Array"
-> GridX = LoopIndex("Load Array") mod (DimX( "Array" ) * DimY( "Array" )) mod DimX( "Array" )
-> GridY = LoopIndex("Load Array") mod (DimX( "Array" ) * DimY( "Array" )) / DimX( "Array" )
-> GridZ = LoopIndex("Load Array") / (DimX( "Array" ) * DimY( "Array" ))

I wouldn't count on it giving a huge boost in performance, but it's worth a try - I mostly just prefer this method because the code ends up much cleaner and simpler than if you use nested loops.

 
n/a

Rob Westbrook



Registered
  25/05/2007
Points
  193

360 OwnerVIP Member
28th June, 2012 at 28/06/2012 21:53:20 -

Thanks Sketchy! Won't it be a bit faster than nested fastloops because MMF will only trigger one (albeit larger) fastloop, rather than 3 separate ones.

 
There are 10 types of people in the world: Those who understand binary and those who don't.
   

Post Reply



 



Advertisement

Worth A Click