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 / Storing arrays in... arrays?

Author
Message
Daryn Alsup
16
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 9th Apr 2013 13:16
Arrays are limited in size by memory available (so I've read and found) But is there some way to reference an array from an array? AKA here's an example.

I make a 16x16 grid of planes each with 64 subsegments. Any more subsegements and I pop the array... is it possible to make another three arrays (sq the total object count or instead of 16x16 planes, it would be 64 by 64)...

example B:
objecta()
Objectb()
objectc()
objectd()
count() <- This would reference the arrays.

I'm not certain if or how it's doable, but, if I can create additional arrays and route them as one, man that's a big terrain.

Any help or insight is appreciated.

I see a lil' byte, its 1/4th a dword, Double float, Double float - but it doesnt beat a Global. Very very frightning, integers dividing me! Look a constant oh a constant. Oh-oh I just want the byte!
ShellfishGames
12
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 9th Apr 2013 13:49
To be honest I don't quite understand what you mean.

However, storing arrays in arrays (i.e. having a reference to another array within a type-definition for instance?) is - as far as I know - not possible in DBP natively unless you choose to use some kind of workaround.
It might be possible that Matrix1 Utils provide this possibility, at least it allows you to access pointers to arrays. Otherwise you might consider creating the "arrays" manually, either by using memblocks, or DBP's memory-commands, or even by using one single big array containing all the elements (for example you could store 10 arrays of 20 elements each using a single array of 200 elements, storing only the ID of the first element of each smaller array within the big one).

I recently wrote a small set of functions to allow the handling of dynamic linked lists (sort of). If this is of any help, I might as well just post it here. It is, however, most certainly slower than the solutions mentioned above due to increased overhead. So when working with huge amounts of data it doesn't really pay off.

Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 9th Apr 2013 13:57
If you want an array of 16x16, with each element having 64 subelements, why not just create an array like this:
Array( 16, 16, 64 )

That way for each X, Z position in the array, you can access all 64 subelements in the same array.

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
Daryn Alsup
16
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 9th Apr 2013 15:38
I have a grid of 16 planes, each with segments (one plane has 64x64 segments) I use a method of inserting the objects into an array, which points to the object number.

@ Mobiius:
If I change the dimensions of the array I will pop (cause an error) so I direct the array global and reference a type which only includes the object number. It looks like this

type number
objnum as integer
endtype

global dim BIGARRAY(8) as number

I use this array with pick object commands to select the objects surrounding the pick object, so that when I terraform, it affects the surrounding objects.

What I want to do is extend the grid of planes * 4 - so that I am referencing 64 X 64 planes and not 16, which I can only do if I reference the 4 arrays (BigArray() +3 more) in an array.

@ Shellfishgames:

Array sizes are limited to a certain data size, which means that if I am referencing "X" amount of vertices in an object, each vertex = a certain size * the amount of vertices, which means 64*64*3*16*16 is the total size of one array, any more and it pops/breaks the game. I need to reference the array somehow so that I can extend the size of the map, and not limit it to 16 x 16... if that clears things up.

I see a lil' byte, its 1/4th a dword, Double float, Double float - but it doesnt beat a Global. Very very frightning, integers dividing me! Look a constant oh a constant. Oh-oh I just want the byte!
Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 9th Apr 2013 15:52
Instead of using arrays and objects, can you not use a terrain object to terraform instead?

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
Daryn Alsup
16
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 9th Apr 2013 15:55
terrains require a heightmap and are too much of a waste on processing power for what I'm doing... I need all available resources - and that means a no go for AT. Mainly because the size of the terrain is selectable by the user and because the grid system has to be uniform with other objects. After the terrain is edited, it's played on - and custom effects have always given me issues with AT - save the AT shaders - which will also eat up my resources.

I see a lil' byte, its 1/4th a dword, Double float, Double float - but it doesnt beat a Global. Very very frightning, integers dividing me! Look a constant oh a constant. Oh-oh I just want the byte!
Daryn Alsup
16
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 9th Apr 2013 16:00
terrains are also limited to 16X16X64X64 (not size but data size)

I see a lil' byte, its 1/4th a dword, Double float, Double float - but it doesnt beat a Global. Very very frightning, integers dividing me! Look a constant oh a constant. Oh-oh I just want the byte!
Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 9th Apr 2013 16:04 Edited at: 9th Apr 2013 16:06
Use blitzterrain, you don't need a heightmap to initialise (or even if you do, you can use a single pixel image, or even created at runtime like my game does.) and can be absolutely huge! And the paid version will allow many many terrains for almost limitless terrain size.

And I don't understand what you mean by terrains being limited to 16x16x64x64? Even advanced terrain can have hundreds of rows/columns and each vertex can be positioned anywhere in 3D space? (Where you got 4 dimensions from I don't know?)

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
Daryn Alsup
16
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 9th Apr 2013 16:11 Edited at: 9th Apr 2013 16:15
Blitz does what I am asking how to do... referencing an array of planes... DBPro can only allocate "X" amount of info per object, and to comphensate Blitz uses either a hand written plugin to reference objects in arrays nonstandard to DBPRo or it uses DBPro's native arrays in order to make endless terrain - I WANT TO KNOW HOW. But since that information isn't available, I want to try this. I remember when blitz was WIP, and i cannot afford nor use blitz with the plugins I have currently in use for the game im making. I have to reference an array somehow and I can't figure it out.

I see a lil' byte, its 1/4th a dword, Double float, Double float - but it doesnt beat a Global. Very very frightning, integers dividing me! Look a constant oh a constant. Oh-oh I just want the byte!
Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 9th Apr 2013 16:46
BlitzTerrain was written in C++ so can use all the variable types it has to offer. (Including arrays in types, structs and all kinds)

Plus, BlitzTerrain is free, Blitzwerks Terrain costs money.

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
Daryn Alsup
16
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 10th Apr 2013 04:52
Blitz plugins were written in c++, yes - but since I cannot do that (and since the plugin allows in one way or another - storing of arrays) I need a work around

I see a lil' byte, its 1/4th a dword, Double float, Double float - but it doesnt beat a Global. Very very frightning, integers dividing me! Look a constant oh a constant. Oh-oh I just want the byte!
Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 10th Apr 2013 14:16
You don't need to know c++, just use the plugin. It handles all the complex stuff, all you need to do is generate it, and update it. Check out the BT demo where there's a huuuuge terrain being deformed by artillery in real time. If you still thing it wont work then set to work re-writing the wheel! lol

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
Daryn Alsup
16
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 10th Apr 2013 14:59
Alright, jetsen - this is the flinstones... I gather not writing - I think you misunderstood me when I said THE DLL for Blitz crashes my application because of a conflicting plug-in AND since this post was about reinventing the wheel (albeit inverted and misrepresented) I will continue doing so, though in the future try not to jump so quickly to an answer - if it were as simple as using blitz - wouldn't I be using it already and thus, saving me lines upon lines of code? Come on... I am going about it this way because there's a road block on the other.

If I could, what other way could I store information other than in arrays (and memblocks which also are limited to the same max size)

I see a lil' byte, its 1/4th a dword, Double float, Double float - but it doesnt beat a Global. Very very frightning, integers dividing me! Look a constant oh a constant. Oh-oh I just want the byte!
Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 10th Apr 2013 16:14
You could use the the DarkData plugin?
Or create a text array and use the Matrix1's split string function to get each element. Not ideal but usable. I use that method in my UI engine since I can't use arrays in types.

For example, Array( X, Z ).Element$ = "1, 2, 3, 4, 5, 6, 7....63, 64"
Now you have an array of XxZ, plus each of the 64 subelements in a string.

And what plugin confilcts with Blitz? maybe it could be worth sorting that conflict out?

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 10th Apr 2013 16:22 Edited at: 10th Apr 2013 16:58
Let's all try to read thoroughly before replying peeps; includes reading my message thoroughly before replying. Hmm.. they should add a read thoroughly button to this post toolbar,.. that would be cool anyway...

I am guessing this information might be useful.

Please don't bother with Dark-Data; it is too slow for what you want; please don't tell me it is faster than arrays without showing me an example; I've got a test on my hard drive showing that it is not worth using Dark-Data for anything whatsoever.

I'd rather you use text lists or XML plugins than Dark Data. Even still, XML plugin use is faster than text lists, and the following is faster than either.


DIY Terrains
Firstly; judging by the messages I get the impression you are not using the Matrix1 utility make plane command; which offers multiple grid parameters for you to create your own terrain mesh. Forgive me if I am wrong and you are in-fact using it. You can manipulate the vertices on it using vertex data commands.


Arrays in arrays
Array to memblock to array
This is a grey area; now, what I was doing not so long ago was storing arrays in arrays using banks (Matrix1 version of memblocks which have unlimited instances), but you can simply use the Make Memblock From Array and forget the banks if you feel 255 memblocks is enough.

What takes place is an array is converted into a memblock, which is then stored in an array. The conversion from array to memblock is minimal, about 1% of one millisecond or so. Frankly, if you look at the memblock of a basic array, it is literally a series of 4 byte integers, or 2 byte words or what ever the datatype is.

Here is some of the source code; you seem knowledgeable so it might make sense:



This snippet WAS my method for storing arrays, in arrays, in arrays and so on. Focus on the ReadValues and WriteValues commands. Ignore the Lg/Throw commands and the other functions.

I have one problem with this method; and I do understand that using banks are not necessary, and may be the cause of the problem; storing strings does not work here, and I get the feeling the values are inconsistent; something is going on. The strings you put in are not the same you get out. I do not trust it; but again it could be the banks.

So what I am saying is, this should work, but seems to not be so, I'm not currently using it in my game; it could be problem with the banks; I haven't got round to investigating it.

Relationships
This is the method I am now using, and was have been for the past 5 years; it is commonly used in the DBP community. I also use variables and PTRs to store special indexes.

There is only one array for each data type. The relationships are indexes stored in each entry.

Here are the link variables in a parent class; First and Last. The first is the first index of the first element added to the parent; and the last is the previously added element.

Each element has a link to the previous, next and first element; this is optional.

Here is an example of looping elements of the same type:


Here is an example of looping elements of a different type:


This method continues to loop until the next element is zero.

Pointers
This method uses a Matrix1 function name or pointer; functions called by a string or numeric representation. The function handles to extraction and insertion of elements.

Here is an abstract example



This example is one step up in complication from the previous one, in that the operations are customizable and are organized by a generic function. Low level programming of such operations simulates an extensible library of functions and arrays.

This one is advanced, but allows you to create more unique relationships. The members of a class are defined in functions as-well as fields.

Blitz Terrain
Excellent plugin; you need to play around with it to get the most out of it; it has its own rendering pipeline which you need to work with. It might be worth using it as the visual representation of your grid.

I hear about what you are saying with re-invention of the wheel, but maybe it would be a cool option to spend your time adding to what's already there. If you feel like making your own terrain system because you think you will be better of without Blitz Terrain, by all means.

What I always say is forget the name of tools; ignore their names; focus on what they can do. Blitz Terrain is actually good at creating things like water and paving.

Daryn Alsup
16
Years of Service
User Offline
Joined: 5th Jul 2008
Location: In your head... dun dun DUN!!!!!!!!
Posted: 10th Apr 2013 17:11
I hear you and that was a very thourough answer - and really I can't thank you enough for that bit of information.

I am in fact using the Matrix1 commands in my strip of code.

The reasoning for the work around is a plug in I'm using. All that I know is that Without the blitz DLL the code works, with the DLL it fails... and to save myself time rewriting code that already does what I want it to on a smaller scale, I am looking for a work around.

I will look into the array memblock array idea as well as the pointer to functions (which may help)

If you care to look, I also have a topic fairly viewable in the list in this forum concerning smoothing the terrain, in which the project is downloadable. There you can examine my code. It is choppy, but can be cleaned up - the structures in which all of the code in question is sitting in is quite 'clean'

The pointer is my best bet looking at its structure and function. Basically if I can duplicate the array holding the object numbers an addition 3 times and direct when the change in arrays should occur, then in theory I should be able to do this... (but again - like all game design it's only theory )

I see a lil' byte, its 1/4th a dword, Double float, Double float - but it doesnt beat a Global. Very very frightning, integers dividing me! Look a constant oh a constant. Oh-oh I just want the byte!
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 10th Apr 2013 18:42 Edited at: 10th Apr 2013 18:44
Quote: "like all game design it's only theory"


Indeed yes!

I can have a look at that thread later on tonight if not tomorrow. To be honest, terrain work is so low down my list that I have not done any terrain work in ages; but I might be able to see the problem.

Meanwhile the creator of the plugin is usually watching his thread here. Probably the best person to ask.

Login to post a reply

Server time is: 2025-05-17 16:00:01
Your offset time is: 2025-05-17 16:00:01