A question on nested types

Previous topic - Next topic

Kryten

Hi folks

Heres one I'm hoping someone could point me in the right direction on. Im currently playing with nested types, and Ive hit a small snag.

Take the following scenario.

I have 4 different types - lets call them

Talien
Tblock
Tbat
TCol_Obj

The last one is a collision object as an axis aligned bounding box, which takes its initial values from the other types as its created.

As I understand it, If I create a TCol_Obj type nested as part of Talien, then that will be stored within the array for the Aliens. Same with blocks, bats etc.

If I Dimpush the TCol_Obj type to a separate array as well, it creates a copy of that type and doesnt actually affect the original.

In this case, how can I loop through only the TCol_Obj types to test for collisions etc in a single pass without going through each array for Aliens, Blocks, Bats etc?
Does the nested type literally become a part of the type its created within, or is it / can it be treated as a separate entity?

Hope that makes some sort of sense!

kanonet

I would do it this way: make an array of TCol_Objs and DIMPUSH one instance into it for each of your Talien etc. Inside your Talien you dont hold a copy of the TCol_Obj, but instead you just hold an integer, which stores the index (position) of the instance in the array. So when you want to access instance of TCol_Obj, you simply access the array with that index.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Kryten

Thanks for the suggestion kanonet, but thats basically what Im already doing.

So I'm guessing that what I was asking isnt actually possible within GLB - ah well, worth a shot.

kanonet

Yeah your Type becomes a part of the other type "by value". What you need would be a pointer member in your containing type - unfortunately thats not possible, to cite Gernot: "Pointers are not Basic." So you need to stick with the index, which isn't a bad way.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

MrTAToad

An alternative would be to get hold of/write an inlined C linked list routine (or perhaps get a library) and then call it from GLBasic

kanonet

Its almost impossible to add c++ written structures to a GLBasic TYPE definition. The TYPEs get converted to c++ in its own header and I know no way to access+modify that header from inside a gbas file, since all your INLINEed c++ code gets copied to other files only.
So to use c++ code for this purpose, he would need to redesign his data structure significantly and IMHO he wouldn't win anything since the index way is a good approach: easy to implement and cheap to use.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Kryten

I'm nowhere good enough to even consider playing with C++ stuff :-)

Thanks for the advice & clarification folks - I was just wondering if Id missed a simpler way of doing things as I have a tendency towards doing thing the more complicated way!

MrTAToad

Yes, doing a linklist yourself would be over-doing it  =D

Kitty Hello

Do another array and store the index.