Re: deleting items from 2d arrays

2009-08-15 Thread Daniel Keep
Sergey Gromov wrote: > Fri, 14 Aug 2009 13:55:18 +1000, Daniel Keep wrote: > >> void dropElement(T)(ref T[] arr, size_t i) >> { >> assert( i < arr.length ); >> arr[i] = arr[$-1]; >> arr = arr[0..$-1]; >> } > > I think it's important to erase the last element after the move to make >

Re: deleting items from 2d arrays

2009-08-15 Thread Sergey Gromov
Fri, 14 Aug 2009 13:55:18 +1000, Daniel Keep wrote: > void dropElement(T)(ref T[] arr, size_t i) > { > assert( i < arr.length ); > arr[i] = arr[$-1]; > arr = arr[0..$-1]; > } I think it's important to erase the last element after the move to make sure no dangling references to unused

Re: deleting items from 2d arrays

2009-08-14 Thread Michael P.
Daniel Keep Wrote: > > > Michael P. wrote: > > Okay, so I'm making a breakout type game in D. Using Derelict. > > I have a 2d array of Block type variables(not important what's in them) > > declared like this: > > Block[][] level; > > and later load into like this: > > level = loadLevel( "level

Re: deleting items from 2d arrays

2009-08-14 Thread Sergey Gromov
Thu, 13 Aug 2009 22:59:37 -0400, Michael P. wrote: > foreach( Block[] ba; level ) > { > foreach( Block b; ba ) > { > if( checkCollision( ball, b.p ) ) > { > //remove the block?? > } > } > } I like Daniel's answer be

Re: deleting items from 2d arrays

2009-08-13 Thread Daniel Keep
Michael P. wrote: > Okay, so I'm making a breakout type game in D. Using Derelict. > I have a 2d array of Block type variables(not important what's in them) > declared like this: > Block[][] level; > and later load into like this: > level = loadLevel( "levels.txt", levelNumber ); > Anyways, what

Re: deleting items from 2d arrays

2009-08-13 Thread Jarrett Billingsley
On Thu, Aug 13, 2009 at 10:59 PM, Michael P. wrote: > Okay, so I'm making a breakout type game in D. Using Derelict. > I have a 2d array of Block type variables(not important what's in them) > declared like this: > Block[][] level; > and later load into like this: > level = loadLevel( "levels.txt"

deleting items from 2d arrays

2009-08-13 Thread Michael P.
Okay, so I'm making a breakout type game in D. Using Derelict. I have a 2d array of Block type variables(not important what's in them) declared like this: Block[][] level; and later load into like this: level = loadLevel( "levels.txt", levelNumber ); Anyways, what I want to do is that when the bal