Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Help with best practices for arrays of objects

Author
Message
aerostudios
17
Years of Service
User Offline
Joined: 20th May 2009
Location: Oklahoma City OK (USA)
Posted: 30th Apr 2014 03:58
I am doing a multitude of things.

1. I am loading 3d objects (.x) files of aircraft. I need to store them (or their ObjID's) in an array. Not sure how to do that.

2. I am loading multiple song files (.mp3) and need store them (or their ObjID's) in an array, and be able to sequence through them.

3. I am needing to load 3 individual billboard objects that are ruwnay/taxiway lights. I will then clone them, or create instances of them and store them (or their ObjID's) in an array.

The main gest of my question is to initiate an array for a colletion of;

.x files ( 58 aircraft to be exact)
.mp3 files ( 15 song files)
.bmp files ( 3 different images, red, blue, white) The total light count is around 1700.

Any help would be greatly appreciated.
VisualProg
17
Years of Service
User Offline
Joined: 31st Mar 2009
Location: RussianFederation, Smolensk
Posted: 30th Apr 2014 09:53
I am doing a multitude of things. <<
No, it`s one task)

I need to store them (or their ObjID's) in an array. Not sure how to do that.<<

Create array:



May use users functions for set up "Model Property" and "Render property for model". And this help you configurate to DBP objects from Array) And if you delete object, then you can create cascade clear texture, model and any joins for object. (no memory leaks).

Next, create array from sounds and musics.

MZ&#1106;[NUL]
Barry Pythagoras
12
Years of Service
User Offline
Joined: 14th Mar 2014
Location:
Posted: 30th Apr 2014 11:00 Edited at: 30th Apr 2014 11:06
When you load an object you always have to give it a number...

Load Object "Spitfire.x",1
Load Object "Hurricane.x",2

So you already have object Id's

When you load an Image you always have to give it a number...

Load Image "Flag.bmp",1

So you already have Image Id's

When you load a sound you always have to give it a number...

Load sound "Spitfire.mp3",1

If you are only storing Id's it isn't going to help you, because the ID can be the object number.

Dim Aircraft(58)

Aircraft(1) = 1 `no difference, it is not helpful.

But sometimes you want the aircraft to have a sound, and a colour.

Dim Aircraft(58,2) `2 = 1 sound, and 1 colour (This is not code)

Aircraft(1,1) `sound

Aircraft(1,2) `Colour

Aircraft(1,1) = 3 `aircraft 1 has sound 3

Aircraft(20,2) = 6 `aircraft 20 has colour 6

That's the way I do it. Then there are types. I don't use types, but someone else will probably tell you how to use them.
VisualProg
17
Years of Service
User Offline
Joined: 31st Mar 2009
Location: RussianFederation, Smolensk
Posted: 30th Apr 2014 11:22
Quote: "Dim Aircraft(58,2) `2 = 1 sound, and 1 colour (This is not code)

Aircraft(1,1) `sound

Aircraft(1,2) `Colour

Aircraft(1,1) = 3 `aircraft 1 has sound 3

Aircraft(20,2) = 6 `aircraft 20 has colour 6 "


It`s no optimally. At the time when the project will be a big (huge), there will be problems with reading the code.

Use "user-types".

MZ&#1106;[NUL]
Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 30th Apr 2014 17:54 Edited at: 30th Apr 2014 19:27
In the most basic sense, an array is just a continuous line of numbers.
It's up to you to decide what series of numbers to allocate for what objects, music, etc.

For example, you could say that your airplane objects were going to be numbers 1-58. If your airplane file names were something like "1-plane.x", "2-plane.x", "3-plane.x", etc. then you could load them with a simple FOR/NEXT loop:



666GO†O666
aerostudios
17
Years of Service
User Offline
Joined: 20th May 2009
Location: Oklahoma City OK (USA)
Posted: 30th Apr 2014 23:15
Thanks guys. I'll let you know which method works best for me.
aerostudios
17
Years of Service
User Offline
Joined: 20th May 2009
Location: Oklahoma City OK (USA)
Posted: 2nd May 2014 04:53
Thanks for your help guys. I was able to load single colored taxiway lights, and then use INSTANCE OBJECT to duplicate them where needed. I've attached an image showing the result.

All of the blue/red/white dots you see are taxiway light images using the billboard approach. There are about 1700 of them total.
Barry Pythagoras
12
Years of Service
User Offline
Joined: 14th Mar 2014
Location:
Posted: 2nd May 2014 11:33
If a plane goes missing in Malaysia we know where to find you!
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 2nd May 2014 21:11
That looks like a nice screenshot. I would like to see more of this in the WIP board.

This seems like a long term project; you need to think in long term when designing your arrays. Scalability, prefabrication, scripting and a touch of polymorphism are a few programming principles you should look into to help make your work less tedious.

In a nutshell, when you need to change a small feature in your program, it should be a small task ideally with no code alteration. I highly recommend posting some code or some pseudo code showing your current procedure so that I and the other guys can steer you in the right direction.

Judging by your comments and the look of your work, you are probably a well skilled programmer who has migrated to DBPRO, who needs just a little direction with this particular tool.

aerostudios
17
Years of Service
User Offline
Joined: 20th May 2009
Location: Oklahoma City OK (USA)
Posted: 3rd May 2014 15:13 Edited at: 4th May 2014 00:04
Hey Chris. I'm pretty sure you and I have chatted via email in the past. There is a post in the WIP board for TOWER CAB. I've been back and forth with this. First wrote it using DarkGDK.NET. Then realized none of the addons worked in VB.NET. So, I opted to try to use the Dark GDK by Mistrel with Purebasic. A problem then surfaced where the sprites used for the foreground interface objects were not be created properly. So, I opted to just use DarkBasic Professional now just as it is, and forget about all the others.

So, here is the code where I created the lights.



To explain what is going on here, the file for the light data was created from AutoCAD. I manually placed a symbol for each colored light over a backdrop of the scene (GOOGLE Earth). I then exported all of those symbols to a text file that contains the color name, x/y coordinates of each light.
So, I read them in, sorting on color name. I then calculate the angle from each point to where the tower cab will be. Each plain is rotated to face the tower cab. Since the tower cab is fixed, and the camera only rotates left/right, using the billboard method was perfect to give the illusion of 3d.
I then set each light to glow on their own. So when the ambient light level goes from day to night, it appears that the lights are on. But, they are set to always be on. I thought about having the user actually do something (Press L) to turn the lights on/off. But its not that big of a deal. I can just say that are controlled by a photocell.

If you can see a cleaner way to write this, I'm open to ideas. I've used a slightly longer way to code this to help me keep it clear in my head.

Here is the link to my WIP post
http://forum.thegamecreators.com/?m=forum_view&t=198407&b=8#top

Thanks everyone.
VisualProg
17
Years of Service
User Offline
Joined: 31st Mar 2009
Location: RussianFederation, Smolensk
Posted: 5th May 2014 16:19
Quote: "So, here is the code where I created the lights."

Good way.

If you want to remove redundancy code, can be combined 3 arrays in an one array:



But, have to add the line "ColorGroup", and the file will be:



MZh[NUL] <--
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 5th May 2014 21:26 Edited at: 5th May 2014 21:29
Hi Aerostudios

I remember your project now. It seems like a long time ago since I last looked at your WIP; It is one of those detailed looking one that get flushed down by an overflow of 'help me' projects and non TGC promotions. It would be good if your WIP could be brought back up again, or maybe a new one is in order.

How is it going? Have you had much time for the task? Have you got much help?

I also attempted to build my projects in Dark GDK. But I ended up using Dark BASIC Professional and VB.NET. I use Dark BASIC for the 3D stuff. The DBP-VB.NET marriage is going OK so far, needs more work.

Now, about the arrays...

I know that you know what you are doing and where you are going. There is no single wrong or right way to make something work, and it seems that you have got it to work. This is just me having a conversation about the problem; one man's solution is just one person's solution; you will know the best solution amongst many for your work because no one else knows all of the details and all of your needs.

The question is what is it exactly that you are unsatisfied with? Is it the fact that you have to export a new list of lights when ever you wish to add a new light to the scene? Is it the fact that you have to recompile your program when you wish to add a new light colour? Or perhaps you would like to improve something else? Once you explain what you desire, then I might be able to direct you more swiftly to what is ideal for your DBP arrays.

In general, the way VisualProg designed the solution adheres to most of the programming principles I studied or stumbled on; all with DarkBASIC in mind. You want to be treating all taxi-lights as taxi-lights when carving your code on stone; there is really no point hard coding their colours. But why stop there, they need not be considered as taxilights; just light sources. That way all other light sources in the airport can reuse the functionality you supplied to your taxilights. For all new functionality identical to existing functionality is in excess; redundant.

I see DBP program as a stone carving hobby; adding new functionality or making changes to code means hours of sweat chiselling away at dense material. The larger the project becomes, the more difficult it becomes to carve out the program. Less time spent having to carve your stone means more time for polishing it; but it takes time to plan how to avoid getting stuck in a loop; I still find myself building my own dungeon of stone carved program features. The IDE is right in front of you so you can develop a habit of throwing ideas straight into the program. This is one of the difficulties of working alone; solutions that spring to mind go straight into the code.

Once you start to keep in the forefront of your mind that hard programming is closer to stone carving than pencil and paper; you are already a step ahead of putting the information in the correct place.

I have not written any code examples because I think I would need to understand your wishes a bit more before I can be of any real help. But to reduce your compile times in the future, I recommend getting into scripting and developing your own convenient file formats, so you can put more of the logic where it is easy to change. If you fancy giving it a go I am willing to give you some support.

But as far as the best way to use arrays in DBP, it depends on your goals; let us know what you are unsatisfied with? There are too many ways to use arrays for me to just slap one or two of them in hope that you end up better off, than picking the type of designs which are close to your needs.

One last recommendation is Vectors; although somewhat pointless looking at first, using vectors to rotate and position all things in your program will help make the program more concise. Consider that all functionality supplied for vectors is functionality supplied to all users of them. Matrix1 utilities provides some great vector shortcuts.

aerostudios
17
Years of Service
User Offline
Joined: 20th May 2009
Location: Oklahoma City OK (USA)
Posted: 19th May 2014 21:09
Hey Chris, good to hear from you.

Yes, TOWER CAB has been a very long project. Its far more complicated than I imagined. I first started it with DB Pro. Then, the debugging was becoming too complex for the editor and I decided to give the DarkGDK.NET a try. I put it aside and created Airline Sharks using the DarkGDK.net, and learned a lot. So, I then went back to working on TOWER CAB in VB with the DarkGDK.NET. I then found Mistrel's GDK he created for Purebasic. Since I had lost the ability of using all of the addons I purchase for DB PRO with .Net, I opted to convert the whole thing in Purebasic. That went okay for awhile, but then discovered a glitch that prevents any of my interface sprites from appearing correctly on screen. All of my PNG files with translucency were lost in the PB version. I could not have that, and have now once again returned to hardcore DB PRO. I have decided to approach the debugging process in other ways, so I can truly benefit from DB PRO in its purest form. Its going well now, but am needing help occasionally in understanding how to translate some things from both PB and VB.NET; which was the reasoning for my questions.

I have now figured out that the best thing to do with multiple copies of 3d objects, is to simply save the Object ID in the array. The lighting problem was solved with everyone's help. I needed to have the ability to load the single red, white and blue lights, and then copy them and place them at the coordinates stored in a text file. The user can then press "L" to toggle the lights on/off; which simply sets the "emissive" property for each light, simulating its own glow. It now works flawlessly.

So thanks to everyone for the help.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 20th May 2014 01:12 Edited at: 20th May 2014 01:16
Yes, I was going to say, use a dynamic array for storing this information. I found doing something like the following is pretty structured, especially when you wrap it into helper functions:



Because then you can do things such as:



And do all of the updating withing the function onUpdateAircraft. If any of the aircraft require special attention (for example, if the player is controlling it), you can save the ID returned so you can process it later:



Your mod has been erased by a signature
aerostudios
17
Years of Service
User Offline
Joined: 20th May 2009
Location: Oklahoma City OK (USA)
Posted: 22nd May 2014 23:35
@TheComet, thanks for the great code tips. I'll definitely explore those techniques.

Login to post a reply

Server time is: 2026-07-06 04:31:20
Your offset time is: 2026-07-06 04:31:20