GLBasic forum

Main forum => GLBasic - en => Topic started by: Kryten on 2015-Jun-27

Title: A question on nested types
Post by: Kryten on 2015-Jun-27
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!
Title: Re: A question on nested types
Post by: kanonet on 2015-Jun-29
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.
Title: Re: A question on nested types
Post by: Kryten on 2015-Jun-29
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.
Title: Re: A question on nested types
Post by: kanonet on 2015-Jun-29
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.
Title: Re: A question on nested types
Post by: MrTAToad on 2015-Jun-29
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
Title: Re: A question on nested types
Post by: kanonet on 2015-Jun-29
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.
Title: Re: A question on nested types
Post by: Kryten on 2015-Jun-29
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!
Title: Re: A question on nested types
Post by: MrTAToad on 2015-Jun-30
Yes, doing a linklist yourself would be over-doing it  =D
Title: Re: A question on nested types
Post by: Kitty Hello on 2015-Jul-01
Do another array and store the index.