Advertisement

Question for TANSTAAFL

Started by July 04, 2001 02:11 AM
3 comments, last by bose 23 years, 7 months ago
Hi! I bought your book today, and first off I can say - it is a very good book. I just had a question from one of the examples: IsoHex14_2 I may be overlooking something, but it seems from the DrawMap() function that this example program draws the ENTIRE map whether it is on the screen or not. The main problem I have been having in my first Iso engine is not being able to figure out the right methods to scroll a map and still only draw the necessary tiles. In my previous post "Map drawing problems" I posted the source of my DrawMap() function (this was before I bought your book, today). I am wondering if you can point me in the right direction as to how to scroll a map and calculate only the necessary tiles to be drawn. If you are curious, what my function does right now is it finds which tiles are to be drawn, but as you try to scroll it jumps around every tile you move across (hard to explain). Thanks for any advice you can provide.
Since I'm up...

You're readjusting your offset before moving the focus to the next cell. That's why it's jumping.

Base the cells you draw on the position of the player in the map. There's very little math involved.

  for (x=Player.X-5;x<Player.X+5;x++)for (y=Player.Y-5;y<Player.Y+5;y++)blit((x-Player.X)*32+320,(y-Player.X)*32+240)  


That's the general idea. Where .X and .Y are locations in the map array, not actual pixel values.

Just keep plugging at it. Also, have you worked up to chapter 14 or did you just skip to there?

Ben
http://therabbithole.redback.inficad.com

Edited by - KalvinB on July 4, 2001 5:01:26 AM
Advertisement
Ok...

I could be wrong, but if you're saying what I think you're saying:

In this function I first set the offset for the very first tile. After that, there are the 2 for loops that just increment the Dest RECT. The drawing actualy works ok, its the scrolling that is completely off =(

If you meant something else let me know...

Oh and when I first got the book I went straight to diamond maps because that was my immediate problem. I had before read the slide map chapter on IsoHex.net, though I am still reading the book from the begining.

Thanks

Edited by - bose on July 4, 2001 11:34:46 AM
In chapters 12, 13, and 14, the entire map is drawn every frame.

later chapters show how to better optimize tile rendering.

Get off my lawn!

Now, I am not sure if I am approaching an isometric tile engine the right way but...

I GOT IT TO WORK!

It was simply the equation for the start RECT that I was getting wrong.

I still want to know about TANSTAAFL''s example though, and if it indeed does calculate tiles for the entire map whether it is in the viewport or not? I know my function is far from optimized - hell it doesn''t even have error checking...

But here is what worked for me:

  bool DrawTiles(){	int x, y, i;	RECT rcDest;	BYTE byTile;	// Tile location of the upper left corner of the screen	int xStart = mapData.xScreen / 44-4;	int yStart = mapData.yScreen / 44;	// Set the RECT of the first tile to be drawn	rcDest.left = (xStart-yStart)*22 + mapData.yScreen/2 - mapData.xScreen/2;	rcDest.top = (xStart+yStart)*22  - mapData.yScreen/2 - mapData.xScreen/2;	rcDest.right = rcDest.left + 44;	rcDest.bottom = rcDest.top + 44;	RECT rcTemp = rcDest; // Will need a backup!	for(x=0; x<35; x++)	{		// if we are on an odd row, i will be TRUE		i = x&1;				// increment the RECT for the next tile		rcDest.top += 22;		rcDest.bottom += 22;		rcDest.left = rcTemp.left;		rcDest.right = rcTemp.right;		if(i)		{			// offset the RECT and tile coord for an odd row			yStart += 1;			rcDest.left -= 22;			rcDest.right -= 22;		}		else		{			// on an even row, increment the coord down 1 full tile			if(x > 0)				xStart += 1;		}		for(y=0; y<17; y++)		{			// current tile coords being drawn			xCurr = xStart + y;			yCurr = yStart - y;						// increment the bounding RECT			rcDest.left += 44;			rcDest.right += 44;			// make sure we arent drawing past the map limits			if(xCurr >= 0 && xCurr <= mapData.xMax && yCurr >= 0 && yCurr <= mapData.yMax && rcDest.bottom > 0 && rcDest.top < 480 && rcDest.left < 640 && rcDest.right > 0)			{				// this is just a makeshift linked list for testing, it works for now				i = mapLoc[xCurr][yCurr].nNumTiles-1;				byTile = mapLoc[xCurr][yCurr].tileData[i].byTile;				// if there is a tile in that spot, BLT it!!				if(byTile > 0)					g_pDDSBack->Blt(&rcDest, mapData.pDDSTileset, &lptileInfo[byTile]->rcLocation, DDBLT_WAIT | DDBLT_KEYSRC, NULL);			}		}	}	return true;}  


As you can see there is little difference from my first function... the thing that fixed my problem was:

rcDest.left = (xStart-yStart)*22 + mapData.yScreen/2 - mapData.xScreen/2;
rcDest.top = (xStart+yStart)*22 - mapData.yScreen/2 - mapData.xScreen/2;

Anyway, i''d appreciate if you could answer my question, TANSTAAFL.

Thanks again

This topic is closed to new replies.

Advertisement