Representing a 3D space for a puzzle game

Started by
3 comments, last by Hollower 15 years, 11 months ago
Hi! I'm creating a project - a library for "brick puzzle games" - like LEGO bricks or domino or whatever, where you need to join bricks in order to build something, according to certain rules. I'm in doubt, because I'm not sure how to represent a 3D space, where the "action" will go on. My idea is that a Brick holds of a reference to set of Units, which is stored in a 3D array (let's call it a Model). Then we have the Space (a container, also holding a 3D Unit array), which has methods like insert(Brick) and remove(Brick) etc. Inserting a Brick to a Space will result in creating references to the Model Units in according fields of the Space. When some action goes on with a Brick in the space, each of the Units tells the space to notify adjacent bricks, (like Notify(0, -1, 0) [coordinates] will notify the Unit above), and then the notified Unit in Model checks some certain conditions. It's the best idea I've come up so far, but I would like to know, if it can be done in a better way. Some concerns: - inserting a Brick creates only references to the Model, so really a Brick won't be creating a new one. However, I don't think a Brick would have any individual properties. Maybe instead of creating a Model as an array I should make it an object class and make all the Bricks instances of some certain model. However, then it would be good to dynamically create new Model classes with different shapes, and I don't know whether it is correct/possible. - the Units don't know their own position (one of the reason is that in my project they are common to all bricks representing the same Model). I mean, an unit at Space[3, 4 ,5] doesn't know that it's coordinates are [3, 4 ,5]. Therefore, a Space instance must carry out all operations. Maybe it should be an Unit's job? - how does a space look in some real game, like Warcraft or Quake? I mean, it's rather not a huge 3D array. I guess that objects somehow broadcast their presence to others (like when you approach a monster and he notices you). However, notifying every object in game about even a slight change also doesn't seem like a solution to me. Could somebody put some light on it? All ideas are very welcome.
Advertisement
How about having each brick store it's own position. This will enable it to render itself too. Each brick could store a pointer to each of it's neighbouring bricks, so when it is asked to notify it's neighbours of a change, it could be done from inside it's own class function without a manager class trying to work out who it's neighbours are. Maybe create an abstract "brick" class, and then derive different types of bricks from this (I'm assuming your going to be having differnt types of bricks with different properties?).

All your bricks could be stored in a manager class which could store all your bricks in a container, and could be responsible for adding new bricks, removing bricks, and calling their render functions when they need to be rendered, as well as ensuring the rules are upheld - can the user place a brick there? if so create a new brick and set its position, set it's neighbour pointers to any bricks that is adjacent to it, etc.

Just an idea of the top of my head, i'm sure someone with more experience than me will be along soon with a better idea :)
Yeah, I store the position in the Brick (however not in the Unit, which is the most basic part).
The problem is that if I represent Bricks in Space which is an Unit Array, storing position inside an Unit would be quite a waste, since Space[1, 2 ,3].position() would return [1, 2 ,3].
I think of another scenario - storing Bricks in a Vector / Hashtable container, and holding Brick's position as a Brick's member. I'm wondering, how a hypothetical SpaceManager would know then, how to check whether there is an Unit in a particular place. The brute-force solution would be iterating through the whole container and checking each Brick's Unit's position. That's probably not the best method ;)
Yea sorry your right. I kind of misunderstood your problem there.
That is a bit trickier :)
Quote:Original post by hc_ra
- how does a space look in some real game, like Warcraft or Quake? I mean, it's rather not a huge 3D array.


Large 3D scenes usually use some form of scene graph [wikipedia] or bounding volume hierarchy [google.]. If there is static geometry like terrain/buildings those are usually stored within a spatial partitioning [wikipedia] scheme like BSP or octree, which is then linked to a leaf of the scene graph.

Quote:I guess that objects somehow broadcast their presence to others (like when you approach a monster and he notices you). However, notifying every object in game about even a slight change also doesn't seem like a solution to me. Could somebody put some light on it?


Any tree-based structure will help cut down the number of notifications to only the important objects. As for which one is "best" that comes down to the specifics of the game and how objects move and interact and I'm not really qualified to do much more than provide the above links for further research.

[Edited by - Hollower on May 15, 2008 4:39:52 PM]

This topic is closed to new replies.

Advertisement