MOD and Arrays

Blitz3D Forums/Blitz3D Beginners Area/MOD and Arrays

AbbaRue(Posted 2004) [#1]
How do I get a 100 X 100 dynamic Array from 10,000 X 10,000 static array.
Let me explain what I mean.
Say I have a world of 10,000 X 10,000 Tiles.
My play area is 100 X 100 Tiles.
Every time I move in any direction by more then 10 Tiles, I want to create a new Array
of 100 X 100 Tiles from the static Array with me at the centre.
Moved over 10 tiles in the static array of course.
How would I do this? I think it has something to do with the MOD math function.
Can anyone help me Please!


BlackD(Posted 2004) [#2]
The quick cheat way of doing it coz i'm tired. I guess u want something quicker?

[Code]
Dim BigArray(10000,10000)
X=720
Y=500

Dim SmallArray(100,100)
FOR i = x to x+99
for m = y to y+99
SmallArray(i-x,m-y) = BigArray(x,y)
next:next
[/code]

+BlackD


BlackD(Posted 2004) [#3]
Er.. let me correct that..
SmallArray(i-x,m-y) = BigArray(i,m)


Whew! :D Now of course this doesn't take care of centering your character, etc, but I guess u can see how it works.

+BlackD


AbbaRue(Posted 2004) [#4]
Oh right. Thanks!
I was thinking of a one dim. array. That would use MOD.
A Two dim. array takes care of that on its own.
I'm using a 2 dim. array, so your example will work fine.
Steps would just be plus or minus 10 in X or Y.


BlackD(Posted 2004) [#5]
Do note however, that this method is extremely slow.. It would be faster to use a single dim array for sure. But the best way would be to create a bank in memory, dump the single dim array in there. Then simply seek to the part of the bank u want and extract it to a new memory bank which you're using externally. As I said, I'm tired and a newbie so I'm not gonna look it up now :) but check out the BANK commands. Especially CreateBank (size), CopyBank src_bank,src_offset,dest_bank,dest_offset,count, and of course, the peeking and poking to get the data in and out. :)

Copying 10000 variables at once as used in my example will take a long time (too long for gameplay!). By using CopyBank u can figure out where u are, and just copy that portion of the bank to a new bank which you're using to display your map data.

+BlackD


BlackD(Posted 2004) [#6]
I'm using arrays for my map data for my RPG too and am going to have to switch to banks for simple speed issues. It means creating a few custom functions, depending on how complex the data is of course. For instance, if you're using a 10000,10000 map (thats friggin huge man! are u sure u need all that space? :)), you'd have to create a minimum 2 meg bank to store tile data alone, assuming you're using a 256-tile set. And if you're using sprites on-top of that, then you'll also need to know whether or not a location is "walkable" or not, seeing as a castle sprite won't be made up of individual tiles - and so forth and so on.. so add another meg onto that bank for "walkable?" data.

THEN if it IS a sprite rather than a tile being drawn there, you've got to know what sprite to draw (and what tile to draw underneath it, in most cases). Not to mention knowing if you'll take damage in a certain area, and how much damage to take, or if such-and-such is a secret-passage (ie, a walkable wall tile), etc.

Perhaps, use map files for different areas so you're working with a much more manageable amount of memory, or read map data directly from the file? 'Dem hard drives are fast these-days. :)

+BlackD


AbbaRue(Posted 2004) [#7]
That post was actually just an example, to get my question across.
What I really want is to create a dynamic Array of a certain size that contains 2 32 bit numbers per cell.
Each of these numbers represents the x,y coords of a 1 meter square in a virtual world.
It is virtual because it is never stored anywhere.
I will then use those x,y coords in a formula that will dynamically create each 1 meter square on the fly.
Kind of like using fractals to create a landscape.
Then a number of these squares will be used to form a 3D mesh with height data, texture data, and plantlife data, water, etc.
That way every time you return to that mesh it will look the same.
This way one could dynamically create an almost endless 3D world.
That is why I needed to know how to create a smaller array from a larger, And redo it every so many steps.
Every time I get to the end of one mesh I want to create a new one in the direction of travel.
The only landscape data stored will be present viewing area.
And speed is not a problem because the new mesh is only made when you cross into the next mesh.
I actually create a number of meshes in a circle around my present area,
then at various points I render new meshes, so the rendering doesn't slow frame rate.
When you quit the game, the only data stored will be the location you were at in the virtual world.
And any game play info like: items found, people met, skills learned, etc.
With this method I hope to create an entire planet dynamically.
I have my mesh tiles made, now I need to apply the height data, and texture data to them dynamically.
My present viewing distance is about 88km in each direction and only uses about 88,000 polys.
I use 65 meshes so I need 65 arrays. Each array stores 729 verticies. So writing them doesn't take long.
The 10,000 X 10,000 array was only an example and will be a lot larger.
About 16 million X 6 million it takes 1000 meters to make 1 km. and my world will be about 16,000 km by 6,000 km
And like I said that array is virtual, it doesn't really exist.
I just need to pass the numbers into my 65 arrays, and scroll those numbers as I walk in any direction.


AbbaRue(Posted 2004) [#8]
If I use memory blocks then I will need to use MOD to poke and peek the points, will I not?
Unless I use 2 mem blocks, one for x and one for y.
Sounds complicated.


eBusiness(Posted 2004) [#9]
No, you will not. In order to load a 2dim array from a bank do it like this: set const maxx to the number of x-position you want. Then peek and poke at the point x+y*maxx, that simple!


Bremer(Posted 2004) [#10]
If you want to stick with arrays you could use offset x/y variables to pick the data directly from the big array.

dim level(10000,10000)
for y = 0 to 99
for x = 0 to 99
  leveldata = level(x+offsetX,y+offsetY)
  ; do whatever you need with the data.
next
next


ofcause you would have to make sure that the offset variables doesn't go past you max level size minus the number of data you pull. In the above example the limit would be 10000-100. That way you don't have to read the data into another array first.