C++ A problem with polymorphism

Started by
12 comments, last by Glak 18 years, 5 months ago
Quote: Conner McCloud answers: Why are edge tiles a distinct type? It seems as though the easiest solution is to just not assign those pointers at all, and drop the entire concept of an edge tile.


Quote:Rip-off answers: how about having only one tile class, and having the edge tiles have NULL pointers to their non-existant neighbours.


Hopefully this can explain why I chose to do it this way:

Each corner of a tile is an independent height. The height of a corner is stored by the tile of which it is the top-left corner. That is each tile stores one height - the height of it's top left corner. The image below illustrates which tile controls the height of each corner:



Notice that the white corners are not top-left corners of any tile. The height of these corners tiles is therefore undefined.

Rather than making these corners a special case, I simply leave them as undefined. This does mean that the tiles they are part of cannot be drawn, or involved in any function requiring knowledge of the corner heights. Therefore such tiles are effectively fake tiles. They are only there to hold a height value necessary for the tiles adjacent to them.
Advertisement
My approach to this would be to store corner heights separately from tiles. All your problems disappear, and none appear.
That's the way I have usually done it. I guess I was just curious to merge the height map array into the tile array. I forgot that height map arrays have dimensions [w][h] while the tile map they represent is [w-1][h-1]

Fortunately I am still designing it so I can change back to the method you suggested.
why not just have the Draw method for edge tiles do nothing?

This topic is closed to new replies.

Advertisement