
-----------------------------------
tyuo9980
Thu May 12, 2011 7:48 pm

How to destory/delete objects?
-----------------------------------
How would you delete a variable after there is a collision made with it?

eg) if you shoot an enemy the enemy dies and disappears, how would you delete the enemy's x and y coords?

-----------------------------------
Raknarg
Thu May 12, 2011 8:00 pm

RE:How to destory/delete objects?
-----------------------------------
You can't. The most common solution to use is a dead/alive boolean variable.

-----------------------------------
tyuo9980
Thu May 12, 2011 8:38 pm

Re: How to destory/delete objects?
-----------------------------------
and then i can resort the true/false ones and then reduce the size of the flex array to save memory!

that was what i was thinking as well. hoped for another way tho. thanks.

-----------------------------------
Raknarg
Thu May 12, 2011 8:41 pm

RE:How to destory/delete objects?
-----------------------------------
Why bother with a flexible array? It's a waste of memory.

-----------------------------------
Insectoid
Thu May 12, 2011 8:44 pm

RE:How to destory/delete objects?
-----------------------------------
Better to not reduce the size of the array, since doing so will cause a lot of lag. Turing doesn't actually resize the array; it makes a new one with the new size, copies everything from the old one into the new one, and deletes the old one. Might as well just use a large array (which also allows you to not increase the size of the array when adding new bullets/enemies).

-----------------------------------
tyuo9980
Thu May 12, 2011 8:50 pm

Re: RE:How to destory/delete objects?
-----------------------------------
Better to not reduce the size of the array, since doing so will cause a lot of lag. Turing doesn't actually resize the array; it makes a new one with the new size, copies everything from the old one into the new one, and deletes the old one. Might as well just use a large array (which also allows you to not increase the size of the array when adding new bullets/enemies).

im making a geo wars pacifism clone. take a look in the new thread that i made in this forum just now. youll see what i mean. i might possibly have over hundreds of objects.

-----------------------------------
Tony
Thu May 12, 2011 9:04 pm

RE:How to destory/delete objects?
-----------------------------------
You could keep a statically allocated array, and an index variable that specifies where the content ends. Then just increment/decrement it when you need more/less space.

-----------------------------------
tyuo9980
Thu May 12, 2011 9:06 pm

Re: RE:How to destory/delete objects?
-----------------------------------
You could keep a statically allocated array, and an index variable that specifies where the content ends. Then just increment/decrement it when you need more/less space.

so like for x : array 1 .. endx of int?

would that work? since the array declaration isnt in the loop. and wouldnt that also make it slower?

-----------------------------------
Tony
Thu May 12, 2011 9:11 pm

RE:How to destory/delete objects?
-----------------------------------
something like
[code]
var my_array : array 1 .. 10 of int
var end_of_array : int := 5

for i : 1 .. end_of_array
  ...
[/code]
you are working with an array of 5 elements, but allocated enough space for 10 items.

-----------------------------------
Insectoid
Thu May 12, 2011 9:12 pm

RE:How to destory/delete objects?
-----------------------------------
More like;
[code]
var foo : array 1..1000 of int
var endx : int := 1
for x : 1..endx
    %do stuff
end for[/code]

Having hundreds of objects is precisely why you do NOT want to use a flexible array. Multiple objects will be created/destroyed every frame, so you'd be creating/destroying the entire array several times per frame. This would slow down incredibly fast.

-----------------------------------
tyuo9980
Thu May 12, 2011 9:15 pm

Re: How to destory/delete objects?
-----------------------------------
ok i see. just one huge array then.

i think 500 elements is enough since ill be sorting.

-----------------------------------
Insectoid
Thu May 12, 2011 9:20 pm

RE:How to destory/delete objects?
-----------------------------------
Sorting is also resource intensive. Might wanna limit how often you sort everything.

-----------------------------------
Tony
Thu May 12, 2011 9:33 pm

RE:How to destory/delete objects?
-----------------------------------
why would you need to sort that array?

-----------------------------------
tyuo9980
Thu May 12, 2011 9:41 pm

Re: RE:How to destory/delete objects?
-----------------------------------
why would you need to sort that array?

well i wouldnt want to waste any more cpu power by drawing unneeded things on the screen so i would have an array of boolean to see how many enemies are still alive and then draw the minimum number of enemies.

-----------------------------------
Tony
Thu May 12, 2011 9:56 pm

RE:How to destory/delete objects?
-----------------------------------
it sounds like you'll be using a lot more CPU resources doing the sorting.

Also, it wouldn't be necessary to sort anything, if your array contains only the elements that are alive.

-----------------------------------
copthesaint
Thu May 12, 2011 11:03 pm

Re: How to destory/delete objects?
-----------------------------------
You can always use demonwasps Hashmap. Very usefull collections are, and very efficent.

http://compsci.ca/v3/viewtopic.php?t=20302&highlight=hashmap

-----------------------------------
tyuo9980
Fri May 13, 2011 4:54 pm

Re: RE:How to destory/delete objects?
-----------------------------------
it sounds like you'll be using a lot more CPU resources doing the sorting.

Also, it wouldn't be necessary to sort anything, if your array contains only the elements that are alive.

yea true. if alive then draw.
