Newgrounds.com — Everything, By Everyone.

Checking login status…

USERNAME:

PASSWORD:

Logging in…

Logged in as:
.
Logging out…
Inbox My Account Log Out


Forum Topic: Linked list 2d tile grid?

(106 views • 7 replies)

This topic is 1 page long.

<< < > >>
Questioning

JackSmack

Reply To Post Reply & Quote

Posted at: 7/12/08 02:44 AM

JackSmack DARK LEVEL 14

Sign-Up: 11/11/04

Posts: 1,122

Howdy. I'm wondering how to set up a 2d grid like a nested array using a linked list Node setup.

It seems a bit tricky to me does anyone have a grasp on this subject?

Visit JackSmack.com and submit your Flash Movies and Games!

BBS Signature

None

WolfAkela

Reply To Post Reply & Quote

Posted at: 7/12/08 02:52 AM

WolfAkela LIGHT LEVEL 08

Sign-Up: 12/19/05

Posts: 2,061

Linked list of linked lists.

Like, setup LinkedList1, which represents your X. Each element in that linked list also contains a linked list (call it LinkedList2, for Y).


None

JackSmack

Reply To Post Reply & Quote

Posted at: 7/12/08 03:10 AM

JackSmack DARK LEVEL 14

Sign-Up: 11/11/04

Posts: 1,122

Ok so what is the proper way to set up linked lists to work like a nested array?

and how do you access the data for use?

Basicly if I want to set up a tile based grid on my playfield with it how would I start?

Visit JackSmack.com and submit your Flash Movies and Games!

BBS Signature

None

JackSmack

Reply To Post Reply & Quote

Posted at: 7/12/08 03:19 AM

JackSmack DARK LEVEL 14

Sign-Up: 11/11/04

Posts: 1,122

so something like this will create a data list that has 14x14 nodes each named "Node#"

var gridsize = 14;

for(size = 0;size<=gridSize*gridsize; size++){
var eval("Node"+size):Node = new Node();
}

but how would I associate these nodes into a grid and then connect them to the nodes north south east and west of each one?

Visit JackSmack.com and submit your Flash Movies and Games!

BBS Signature

None

DougyTheFreshmaker

Reply To Post Reply & Quote

Posted at: 7/12/08 04:47 AM

DougyTheFreshmaker NEUTRAL LEVEL 02

Sign-Up: 07/30/07

Posts: 480

so something like this will create a data list that has 14x14 nodes each named "Node#"
var gridsize = 14;

for(size = 0;size<=gridSize*gridsize; size++){
    var eval("Node"+size):Node = new Node();
}

PLEASE don't do this! Use arrays (usually) or just give your nodes some sort of ID if you need it.

but how would I associate these nodes into a grid and then connect them to the nodes north south east and west of each one?

Give each node some position information and 4 Node references, north, south, east, and west. There's probably a more efficient way, but building the map row by row (probably populating the 'east' references, maybe the 'south' ones for your list of lists) and then doing a second pass to populate the other nodes would be the most straightforward way.

There are some major differences between Arrays and lists, and one of those major differences is that you can't directly access anything except for the beginning of a linked list (the end as well if you're using a doubly linked list). You'll need to start at a head node and walk through the nodes one by one to get to the position you want.

AS2 or AS3? I'm only "really" familiar with AS3, so I don't wanna go writing a bunch of code if you're not going to be able to get it, though I'm pretty sure the two languages are close enough if you're careful with AS2.

Anyway, just some general comments. It may be worth making one dimension of the grid an Array as you get the direct access ability and simple code of the Array and still manage to save a lot of space in the end (I assume that's the what you're after with a sparse grid like this?). For instance, in a 5000x5000 map, using a multidimensional array would use require storage for 25,000 tiles (50mb at a conservative 2 bytes per file, tile ID and 'next' pointer... probably much more in practice), but the one with the Array and linked list would only require 5000 + <number of tiles used> (down to 5mb + some extra), which is still a pretty huge saving (given a sparse map) with a little benefit to performance. Besides, you're probably unlikely to have a any rows across the whole map with absolutely no tiles in them, so you'd end up having to throw in a head node for a list in all 5000 spots on that first column anyway, actually wasting more space (a linked list requires that extra pointer at the very least, which arrays do not).

As well, depending on how sparse your map ends up being, the type of graph you're after (with each tile pointing to every other tile that it borders) may end up costing quite a bit of extra space/processing time. Also, it'd require some leg work, but I think you can have Arrays with non-consecutive indicies which will be implemented internally using some sort of hash or sparse array anyway, which may do everything you want FOR you.

Not sure if that makes sense... I drew a picture (with only east links) though FWIW

Linked list 2d tile grid?

We should take care not to make the intellect our god; it has, of course, powerful muscles, but no personality.
Freshmaking
Brainscrape

BBS Signature

None

DougyTheFreshmaker

Reply To Post Reply & Quote

Posted at: 7/12/08 04:56 AM

DougyTheFreshmaker NEUTRAL LEVEL 02

Sign-Up: 07/30/07

Posts: 480

For instance, in a 5000x5000 map, using a multidimensional array would use require storage for 25,000 tiles (50mb at a conservative 2 bytes per file, tile ID and 'next' pointer... probably much more in practice),

Rather
5000 * 5000 = 25,000,000
25000000 * 2 (make this 7 for south+north+west and 2 ints for x/y, plus maybe more for tile id etc) = 50000000
50000000 / 1024 / 1024 = 47.68 megs

We should take care not to make the intellect our god; it has, of course, powerful muscles, but no personality.
Freshmaking
Brainscrape

BBS Signature

None

JackSmack

Reply To Post Reply & Quote

Posted at: 7/12/08 06:25 AM

JackSmack DARK LEVEL 14

Sign-Up: 11/11/04

Posts: 1,122

First off AS2. I just got CS3 though I have not installed it yet.

Let me explain what I'm trying to do perhaps if you know my goal you will have a quick fix for me.

I want to select a point on the grid and check if the four points around it are the same value. if they are the same value I want them to check the points around them to see if THEY are the same value.

I will be changing the value of this group, and the section of the grid that has the same value and is directly connected to the group should grow when the value is changed to match the points around the group.

so if I have a red square next to another red square with green squares all around both of them I want to be able to change the associated variables in the array to change the color to green... then if I do it again the green blocks that were not a part of the group to begin with are now a part of the larger mass of blocks that change color when I switch them.

It's kinda coplicated to explain but it's not that difficult if you see it in action I don't think.

Visit JackSmack.com and submit your Flash Movies and Games!

BBS Signature

None

Rustygames

Reply To Post Reply & Quote

Posted at: 7/12/08 07:17 AM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,426

At 7/12/08 06:25 AM, JackSmack wrote: First off AS2. I just got CS3 though I have not installed it yet.

Let me explain what I'm trying to do perhaps if you know my goal you will have a quick fix for me.

I want to select a point on the grid and check if the four points around it are the same value. if they are the same value I want them to check the points around them to see if THEY are the same value.

I will be changing the value of this group, and the section of the grid that has the same value and is directly connected to the group should grow when the value is changed to match the points around the group.

so if I have a red square next to another red square with green squares all around both of them I want to be able to change the associated variables in the array to change the color to green... then if I do it again the green blocks that were not a part of the group to begin with are now a part of the larger mass of blocks that change color when I switch them.

It's kinda coplicated to explain but it's not that difficult if you see it in action I don't think.

Don't install CS3 unless you plan on coding AS3. CS3 is a much buggier peice of software then Flash 8.

Also, if you're having difficulty with such a simple programming task, I assume you're not a confident Actionscripter. In this case for you to go freelance, you're going to need to read at least 1 of these books.

Actionscript for Flash MX: The Definitive Guide
and
Essential Actionscript 2.0

- Matt, Rustyarcade.com


All times are Eastern Daylight Time (GMT -4) | Current Time: 04:22 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!