Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411574 Posts in 69386 Topics- by 58444 Members - Latest Member: darkcitien

May 04, 2024, 05:06:22 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Interconnecting Multiple Area 'Nodes'
Pages: 1 [2]
Print
Author Topic: Interconnecting Multiple Area 'Nodes'  (Read 3190 times)
Sos
Level 8
***


I make bad games


View Profile WWW
« Reply #20 on: March 12, 2010, 02:15:59 PM »

You're right, we suck.

Please don't take offense... I'm not taking a jab at anyone's ability. I just don't see the which language debate being particularly productive or relevant (in this case). As I said, I do appreciate the input regardless of which programming language it is presented in.

Please don't take my recent attacks of sarcasm too seriously. And you're right, it's me who should apologize. I didn't even contribute anything helpful to this thread. Gentleman
Logged

Radnom
Level 8
***


BANNED


View Profile
« Reply #21 on: March 12, 2010, 05:30:29 PM »

Couldn't you just have a static ID int variable, increment on room initialisation and use that as the unique ID?

It's simple, fairly elegant, and every ID is different..
Logged

Will Vale
Level 4
****



View Profile WWW
« Reply #22 on: March 12, 2010, 05:45:01 PM »

Guys, I mentioned the phrase 'made up pseudocode' in the OP because I was asking for a language agnostic design pattern.

Sorry, missed the pseudocode bit!

If your topology isn't arbitrary - e.g. your rooms lie in a 2D grid, and connections are only N/S/E/W, then you have more options. For example storing the rooms in a 2D array and having per-room flags to say which directions are exits. Then getting the next room is defined by the direction and the grid. But I'm guessing this isn't the case from the OP?

If your topology *is* arbitrary, interconnected rooms with arbitrary topology form a graph. The rooms are the nodes, and the connections are edges. There's lots of computer science research about representing graphs, might be worth looking at.

For something I was working on recently, where I was modifying things on the fly, I stored the nodes and edges in two arrays, and the nodes didn't know about the edges. It meant a fair bit of trawling the edge array to find relevant connections, but it wasn't really the performance problem I was expecting it to be. I think for most uses this is overkill though, and the solution where the room contains the connections as per your pseudocode is easier.

Certainly something I will keep in mind, though I would definitely include a check against all existing IDs (even if the chances are quite slim, I can't simply trust the RNG to never pick the same number twice.)

If you want to generate unique IDs, I think you'd be much better off doing:

Code:
new_id = generator
generator = generator + 1

then you know you'll never get a collision until the generator wraps around, and you don't need to mess around detecting collisions. If you have a large generator (32-bit and up) you can pretty much ignore the wrap around. It doesn't matter that they're random or not, isn't the uniqueness the point?

[edit: Radnom just said the same thing in fewer words!]

Will
Logged
st33d
Guest
« Reply #23 on: March 13, 2010, 02:37:49 AM »

Certainly something I will keep in mind, though I would definitely include a check against all existing IDs (even if the chances are quite slim, I can't simply trust the RNG to never pick the same number twice.)

Nonsense.

Simply fill an array with numbers or IDs and then shuffle it with this:

Code:
package com.robotacid.util.misc {
/* Does just what it says */
public function randomiseArray(a:Array):void{
for(var x:*, j:int, i:int = a.length; i; j = Math.random() * i, x = a[--i], a[i] = a[j], a[j] = x);
}

}

Then you can iterate through a randomised list. Random numbers. Never the same number twice.
Logged
BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #24 on: March 13, 2010, 03:48:50 AM »

That's the most annoying piece of code I've seen in a while  Embarrassed. Unhelpful comment, poorly named, deliberately uses an obscure way of writing for the sake of a few lines, twice. Impressive.

But also, I don't think that really helps the problem at hand. That would never give the same number twice, up until you ask for too many number's at which point it fails. I don't see what it's gaining you over auto incrementing.
Logged
Mikademus
Level 10
*****


The Magical Owl


View Profile
« Reply #25 on: March 13, 2010, 04:19:42 AM »

but can we please stop with the C vs C++?
Hey, it was a refreshing break from Java vs. C++!
Logged

\\\"There\\\'s a tendency among the press to attribute the creation of a game to a single person,\\\" says Warren Spector, creator of Thief and Deus Ex. --IGN<br />My compilation of game engines for indies
st33d
Guest
« Reply #26 on: March 13, 2010, 05:01:20 AM »

That's the most annoying piece of code I've seen in a while  Embarrassed. Unhelpful comment, poorly named, deliberately uses an obscure way of writing for the sake of a few lines, twice. Impressive.

 Gentleman

And I didn't even write the original. That was in javascript (hence the one line of unreadable code).

I was addressing the comment about getting unique random numbers. I wasn't decrying the object id method.

I actually have radnom's method of a static incrementing counter already implemented on all my map objects as a debugging tool. It's very useful.
Logged
Pages: 1 [2]
Print
Jump to:  

Theme orange-lt created by panic