Tuesday, July 01, 2003

Big rant.
Or I had a go at hacking together my engine without really knowing enough and I got a bit stuck

Currently at an impasse. I need to organize my thoughts and the best way to do this, I find, is to write a long
rambling text that expresses them.

The issue is that of the tile scrolling and the camera moving.
The 3D realm provides me with new options compared to the previous 2D one.

Roughly the map is made from tiles. Each tile is a textured quad.
These tiles are placed upon the screen according to some data structure portaining to be the map.
Once placed we wish to move about this map that may be bigger than we can see.
But we don't want the clunky jumping movements of an entire tiles width or height at a time.
Instead we wish the map to scroll pixel by pixel.

The Way I Was Going To Do This

Each tile has no idea of its position in the world. Its not ever going to move, it need not know about its realtion
to the world at large. The map data structure takes care of this it knows where all the tiles go.

The map looks at its matrix, and says tile (0,0) you shall be plotted at the top left hand corner of the screen, and
all shall be good. Tile (1,0) you shall be plotted a the top of the screen 32 pixels from the first tile along.
In this way the map would blit all tiles to the screen.

Lets say our world is big, its made up of several maps in a meta matric structure.
A matrix of maps is the world, a matrix of tiles a map.

So we're in the corner of one map, we might be able to see into three other maps!
Therefore the screen needs to be built with chunks of tiles from each of these four (altogether) maps!
Therefore we would need a function
plotMapPartial(x,y, map, tile_x, tile_y);

This way we can plot any parts of a map we might wish to any area of the screen. This is a potentionlly complicated

So what are we doing here - we have a fixed camera looking at the tiles.
Every frame we use immense computer speed to rearrange these tiles.
Maybe we move them all over to the right and introduce some new ones in the left hand column.
We can do this copmuters are zippy fast.
Then when the next frame appears on the screen - blammo - it appears we moved to the left.

UpSides: Pixel by Pixel Scrolling, Several Maps on Screen at once, Potentially unlimited world area
DownSides: Functions are on the complicated side

The Second Path

DirectX3D throws you into a world that already has some sublayer.
It knows there is an origin a (0,0,0).
All models are plotted according to this origin.
A sqaure will have some (x,y,z) that is its distance from the origin.
So we have these lines spreading to a tricorner of infinifty.
The world is plotted out, you can go some where in it and say "Here I am at (9,2,1)"

The key change that could be made here is we move the camera instead of the world.
Before we have a (0,0) and as we moved across we would slowly move new tiles into old tiles positions.
If we moved far enough in one direction (0,0) would eventually be replaced.

Instead we give each tile its own sense of place in the world at large.
Tile (0,0,0) is tile (0,0,0) no amount of moving about on the map is every going to change that

As we scroll the camera across the world we might move into an area dictated by a new map
say (10, 10, 0) we can see three new maps again but they don't need to replace any old tiles
They exits in the teens (11, 10, 0) and so forth.

The wrapping around the world problem! This is indeed a problem.
The only solution I can think of is a bodge, when we get to tile were there is no tile
we just load in the first map again.

So the to do list:

Decide tile sizes 32x32
Texture size will be 256 x 256
Chars will be a little skinnier 32X64 probably.

Done that.

Now assign texture co-ords

... an hour or two later

Okay that doesn't seem to work. What are my problems?
-My main render loop ends
-When I take a single interation out it runs okay
.. I don't see it on screen (see later point)
-Seems to hang on trnasforming co-ordinates, I could be doing this incorrently

The map isn't as simple as I thought with global co-ords
(0,0,0) is center of the screen. To do the upper left hand corner I need negatives
This makes generating my tile coordinates not very easy.

I don't really now how to plot out a level - i.e. I need to learn more
Post a Comment