| View previous topic :: View next topic |
| Author |
Message |
blindcoder Newbie
Joined: 03 Jan 2003 Posts: 28
|
Posted: Mon Jan 13, 2003 6:24 am Post subject: Help needed with Data Structure |
|
|
Hi people
| Code: |
*-------* *-------* *-------*
/ \ / \ / \
/ \ / \ / \
* * *-------* * *-------* * *
\ / \ / \ /
\ / \ / \ /
*-------* * *-------* * *-------*
/ \ / \ / \
/ \ / \ / \
* * *-------* * *-------* * *
\ / \ / \ /
\ / \ / \ /
*-------* * *-------* * *-------*
/ \ / \ / \
/ \ / \ / \
* * *-------* * *-------* * *
\ / \ / \ /
\ / \ / \ /
*-------* * *-------* * *-------*
\ / \ /
\ / \ /
*-------* *-------*
|
I need/want to implement a data structure for the above in C / C++.
The big deal is:
Currently I have each hexagonal in a 2-Dimesional Array. The Problem with that is that I need to hold information on each point (*) twice that way.
I also need to hold information on each point like: has_building, is_occupied et al.
So I thought if there is a way to hold the information not per hexagon but per point.
Unfortunately, the dispalying of the field is not as easy as a quadratic field where I just have 4x4 or 8x8 or whatever.
Has anyone already implemented something like that or has knowledge about how to do so?
blindy _________________ The blindCoder shows us the way. |
|
| Back to top |
|
 |
SpoonMeiser Happypenguin Veteran


Joined: 09 Jan 2003 Posts: 217 Location: London, England
|
Posted: Thu Jan 16, 2003 8:11 am Post subject: |
|
|
I don't understand what you're trying to say... are the *s in the hexagons different to the *s at the corners?
If you're just laying out a map, then each hexagon should contain (weighted?) connections to each of the hexagons it touches, this allows you to easily implement route finding algorithms... they don't even need to know where they, or the hexagons they touch are.
If that's what you're trying to do.
you can then have a 2D array of hexagon objects, and render it just like a map made of squares, except that every other column is ofset vertically by height/2.
There is a Battle Isle clone for Linux, if this is for something similar, you might try looking at their code, it's called Advanced Strategic Command (I believe). |
|
| Back to top |
|
 |
johannesprix Newbie

Joined: 29 Jun 2002 Posts: 39 Location: Graz, Austria
|
Posted: Thu Jan 16, 2003 9:55 am Post subject: Should be availabe for copy-and-paste operation from Gnoca.. |
|
|
| Also Gnocatan *must* be using similar structures, since the game also deals with inside of hexagons and the six margin lines of the hexagon and stores similar information like building in one of the corners or street between two corners and type of the inside of the hexagon. (Hope you're doing a GPL'd program, or otherwise copy-and-paste from there is not allowed...hehe) |
|
| Back to top |
|
 |
blindcoder Newbie
Joined: 03 Jan 2003 Posts: 28
|
Posted: Sat Jan 18, 2003 1:36 am Post subject: |
|
|
Actually I'm writeng a Settlers/SerfCity/Die Siedler 1 type of game.
Since I don't yet know which license I will use, I won't have a look ot Gnocatan (yet), but thanks for pointing it out to me.
Actually I've now developed a possible layout htat wauld also allow me ease of use with scrolling:
| Code: |
o *---o---* o o o *---o---* o o o *---o---* o
/ \ / \ / \
/ \ / \ / \
* o * o *---o---* o * o *---o---* o * o *
\ / \ / \ /
\ / \ / \ /
o *---o---* o * o *---o---* o * o *---o---* o
/ \ / \ / \
/ \ / \ / \
* o * o *---o---* o * o *---o---* o * o *
\ / \ / \ /
\ / \ / \ /
o *---o---* o * o *---o---* o * o *---o---* o
/ \ / \ / \
/ \ / \ / \
* o * o *---o---* o * o *---o---* o * o *
\ / \ / \ /
\ / \ / \ /
o *---o---* o * o *---o---* o * o *---o---* o
\ / \ /
\ / \ /
o o o o *---o---* o o o *---o---* o o o o
|
the o and * symbolize the 2D-Array with every item being in one of four states:
Intersection left (connections to upper left, lower left, right)
Intersection right (connections to upper right, lower right, left)
Center (no border)
none (not to be used by the player)
And yes. this creates a whole lot of overhead, but with scrolling I just memcpy lines 0 to end-1 over lines 1 to end and the last line over line 0 and scrolling is done.
I'm currently implementing this method and will report on success or failure.
Thanks for the help,
blindy _________________ The blindCoder shows us the way. |
|
| Back to top |
|
 |
trick Happypenguin Veteran


Joined: 04 Dec 2002 Posts: 210
|
Posted: Sun Jan 19, 2003 9:07 am Post subject: |
|
|
That seems to be wasting a lot of space to me, if i understand this correctly - os are unused ?
Remember that the cells doesn't have to look like hexagons in memory - as long as they have six edges, you're fine. So something like this...
| Code: | *--* o *--* o
| \ | \
| \ | \
* * *--* * *
| / | /
| / | /
*--* * *--* o
| \ | \
| \ | \
* * *--* * *
| / | /
| / | /
*--* * *--* o
\ |
\ |
o o *--* o o |
..might be better, depending on your needs.. |
|
| Back to top |
|
 |
SpoonMeiser Happypenguin Veteran


Joined: 09 Jan 2003 Posts: 217 Location: London, England
|
Posted: Sun Jan 19, 2003 3:49 pm Post subject: |
|
|
| wasn't Settlers layed out as rows of triangles, ie. every point had 6 neighbours, ne, nw, e, w, se and sw. A building could have been built on one of these points and a road could connect 2 points. Again, this could be organised in memory as a 2D array, but rendered with every other row offset somewhat. |
|
| Back to top |
|
 |
blindcoder Newbie
Joined: 03 Jan 2003 Posts: 28
|
Posted: Sun Jan 19, 2003 11:45 pm Post subject: |
|
|
SpoonMeiser: yes, that's exactly what I'm currently trying to do.The problem is that a map made of hexagons (6 points) cannot be handled as easily as a map made of quadrats (4 Points) which could be put into memory easily.
trick: Looks interesting, I'll give it a try.
I have the structure with my first approach now implemented but it really _does_ toke up a huge amount of memory (even with a very small map). Let's see what trick's approach brings :) _________________ The blindCoder shows us the way. |
|
| Back to top |
|
 |
SpoonMeiser Happypenguin Veteran


Joined: 09 Jan 2003 Posts: 217 Location: London, England
|
Posted: Mon Jan 20, 2003 7:46 am Post subject: |
|
|
My point is that you're confusing yourself by thinking of it as a map of hexagons.
| Code: |
*-----*-----*-----*
\ / \ / \ / \
\ / \ / \ / \
*-----*-----*-----*
/ \ / \ / \ /
/ \ / \ / \ /
*-----*-----*-----*
\ / \ / \ / \
\ / \ / \ / \
*-----*-----*-----*
|
is what it should look like.
of course, this could be thought of as a 2D array:
| Code: |
*--*--*--*
| /| /| /|
|/ |/ |/ |
*--*--*--*
|\ |\ |\ |
| \| \| \|
*--*--*--*
| /| /| /|
|/ |/ |/ |
*--*--*--*
|
|
|
| Back to top |
|
 |
blindcoder Newbie
Joined: 03 Jan 2003 Posts: 28
|
Posted: Mon Jan 20, 2003 11:24 pm Post subject: |
|
|
*argh*
that's so obvious that it hurts...
I have to draw the hexes as several triangles _anyway_ so why didn't I notice it myself >_<
Thanks for pointing this out to my blind self. I'll give it a try asap but that will probably not be before weekend.
blindy _________________ The blindCoder shows us the way. |
|
| Back to top |
|
 |
blindcoder Newbie
Joined: 03 Jan 2003 Posts: 28
|
Posted: Thu Jan 30, 2003 11:33 am Post subject: |
|
|
Okay, it's finally done :-)
I've set up a little page to let everyone who is interested (that would me only me :) what's going on.
http://www.crash-override.net/freeserf/ _________________ The blindCoder shows us the way. |
|
| Back to top |
|
 |
trick Happypenguin Veteran


Joined: 04 Dec 2002 Posts: 210
|
Posted: Thu Jan 30, 2003 1:57 pm Post subject: |
|
|
| Love the screenshot =) |
|
| Back to top |
|
 |
SpoonMeiser Happypenguin Veteran


Joined: 09 Jan 2003 Posts: 217 Location: London, England
|
Posted: Thu Mar 27, 2003 4:22 pm Post subject: |
|
|
possibly an easier data structure to use would be if the map wrapped around on one axis, then the representation of the map could look like this:
| Code: |
-*--*--*--*-
/| /| /| /|
|/ |/ |/ |/
-*--*--*--*-
/| /| /| /|
|/ |/ |/ |/
-*--*--*--*-
/| /| /| /|
|/ |/ |/ |/
-*--*--*--*-
|
the adjacent nodes of each node are at the same relative positions each time:
(x, y-1)
(x+1 % width, y-1)
(x+1 % width, y)
(x, y+1)
(x-1 % width, y+1)
(x-1 % width, y) |
|
| Back to top |
|
 |
Guest
|
Posted: Thu Mar 27, 2003 5:10 pm Post subject: |
|
|
If I could recommend Isometric Game Programming for DirectX (ignore that part.. it works for any system)
It'll detail some very good examples on how to do hexes and the like. |
|
| Back to top |
|
 |
|