Adding emtpy rows and columns to a two dimensional array with DIMPUSH

Previous topic - Next topic

S.O.P.M.

Good morning,

I wonder how to use DIMPUSH in the following way, if possible. I've a 128 x 24 two dimensional array and I'm looking for an easy way (as less code as possible and standard basic only, of course) to add emtpy rows and columns to it.

To add these rows/columns below and on the right side I simply can REDIM that array - everybody knows that. But I also want to add on top and on the left side! Then I have to shift the array contents element by element which could be quite slow and inefficient. How can I use DIMPUSH for that?

What I also want to know is, how do professional programmers handle this situation high efficient with any array they use in their application? With the same code/function? Working with lists maybe?

The perfect solution for me would be to have one single function where I can pass every array and add a row or columns on every position. For example something like AddColumnRow(Array[], [Row][Column], Position)

Thanks for your attention, have a good day.

-S.O.P.M.-
Notebook PC Samsung E372 Core i5 @ 2,6 GHz; 4 GB RAM; Win 7 Home Premium

kanonet

I think you already mentioned what could be done using GLBasic. Of cause when oyu know how much space you will later need on top/left you could simply leave out that room and fill it later when needed.

When you would also consider using INLINE, I would go with memcpy and things like that. But also reconsider the structure of your data, maybe the same result could be achived, when you rearrange your data differently.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Schranz0r

INLINE and List<whatever_type_you_need> should work...

you can hold a 2D array in a 1D array as well.


You can do it like this:

http://stackoverflow.com/questions/1817631/iterating-one-dimension-array-as-two-dimension-array
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

S.O.P.M.

That sounds like a great idea to save 2D data in a one dimensional array. I've a borderless operating level editor where the user can add objects at any position as long as the width and height of the entire structure doesn't exceed set limits. So I always have to shift data within the whole array. But now as I realized that DIMPUSH also doesn't do the job because it doesn't matter if I work with one or two dimensions I... :S
Notebook PC Samsung E372 Core i5 @ 2,6 GHz; 4 GB RAM; Win 7 Home Premium

kanonet

Actually internally GLBasic does always use a 1-dim array, all other dimensions are only simulated on top of that.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Marmor

why not use a second array what handle the order ?

every insert creates a new fieldnumber , so you can grow your array with redim but the real order
is stored in the second array.

no insert needed and for drawing use the second array in combination with your playfield.

mfg

kanonet

I think this could be considered GLBasics version of a linked list, but its a good idea.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Schranz0r

I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Moru

If this is an editor that needs copy/paste functions, you might as well just make a move function that redim and then move the content as you suggested in the first post. What is wrong with this solution? Less lookups and more speed later when drawing. If this array only contains indexes into your block data anyway, this is move can be done in real-time every screen frame without even noticing anything.

I'm sure my Atari would handle an array with 128 x 24 integers without breaking out in a sweat even :-)

What I'm trying to say is: Don't optimize one-time operations, make sure that draw routines that will be called 60 times per second runs as lean as possible instead. (Now I don't know if this resize you plan is a one-time thing but it sounds like it is something the user can do with a button-click so it's nothing that needs to be done 60 times per second.)

Marmor

But the Problem itself is interesting imho.
My first idea was to make a big array and create a center (0,0) in the middle.
But this solution are bounding also.

Moving elements in an editor to create
a easy brainfriendly array is also ok imho
Because u need no new arrangement in the
Game , so this is a speedup.

If you use inline i would go with memcopy
Because its faster als a for next.
I think also about an cartesian coordinate arranged
Array imho the easyest way for an editor.
U can add the 3. Dimension also easy with using a second array.

Mfg

S.O.P.M.

Thank you very much, it becomes really interesting here but have to say not able to follow in any aspect. Actually my game (or better, the editor of it) runs smooth at 60 fps on my SGS3 phone at this time. I think the best way to continue is to first show you in detail what I'm speaking about. So please wait for a short video demonstration I'll upload till tomorrow.
Notebook PC Samsung E372 Core i5 @ 2,6 GHz; 4 GB RAM; Win 7 Home Premium

Moru

It's always hard to give advice if you don't have all the details so that would be nice :-)

S.O.P.M.

Ok, here is some video to show the editor in action. You can see at the end, borders will be shown as soon as objects are placed in the array. Dependent on the overall width and height of all objects, borders will change. So it's always possible to place new objects at any position as long as the overall size remains legit.

http://youtu.be/mM8h8qBdWEg
Notebook PC Samsung E372 Core i5 @ 2,6 GHz; 4 GB RAM; Win 7 Home Premium

erico


Kitty Hello

You must move the contents if each cell. No way around that. Lists (pointer liszs) of that size are WAY slower than arrays.

Gesendet von meinem GT-N7100 mit Tapatalk