Jump to content
  • Advertisement
  • entries
    707
  • comments
    1173
  • views
    436781

This sucks...

Sign in to follow this  
Programmer16

369 views

I was hoping to be able to post a screenshot of my 2D demo today, but for some reason fringing/transitions won't work. I'm getting the following results blended together:
1 - top
2 - right
3 - bottom
4 - left
5 - corners of the same side

1 1
1 5 (so the lower right corner would be topleft trans and top right)

2 2
5 2

5 3
3 3

4 5
4 4

So each one is the exact same thing, just rotated. I have no clue what I'm doing wrong. I'm using the code (not copy and pasted, but checked thoroughly) from TANSTAAFL's book (he uses iso tiles, and I tried switching to iso tiles, but it didn't help.)

Here's my code for it if anybody wants to help (before anybody says anything, yes I know it is very very hacked and very very slow, I just want to get something working before I start coding a project.) This problem has nothing to do with the engine, but I still need to solve it lol.
Values

enum ISODIRECTION
{
ISO_NORTH = 0,
ISO_NORTHEAST = 1,
ISO_EAST = 2,
ISO_SOUTHEAST = 3,
ISO_SOUTH = 4,
ISO_SOUTHWEST = 5,
ISO_WEST = 6,
ISO_NORTHWEST = 7
};

enum ISOZONES
{
UPPERLEFT = 0,
UPPERRIGHT = 1,
LOWERRIGHT = 2,
LOWERLEFT = 3,
};

int FringeLookUp[8] = {-1, 0, 1, 1, 2, 3, 1, 1};



Map Node class

class MapNode
{
public:
unsigned int m_nTileNumber;
unsigned int m_nTileSetID;
int m_iFringe[4];

MapNode()
{
m_nTileNumber = 2;
m_nTileSetID = 0;
m_iFringe[0] = 0;
m_iFringe[1] = 0;
m_iFringe[2] = 0;
m_iFringe[3] = 0;
}
};



TileWalk()

POINT TileWalk(POINT Start, unsigned int nDir)
{
switch(nDir)
{
case ISO_NORTHWEST:
{
--Start.x;
--Start.y;
break;
}

case ISO_NORTH:
{
--Start.y;
break;
}

case ISO_NORTHEAST:
{
++Start.x;
--Start.y;
break;
}

case ISO_EAST:
{
++Start.x;
break;
}

case ISO_SOUTHEAST:
{
++Start.x;
++Start.y;
break;
}

case ISO_SOUTH:
{
++Start.y;
break;
}

case ISO_SOUTHWEST:
{
--Start.x;
++Start.y;
break;
}

case ISO_WEST:
{
--Start.x;
break;
}
}
return Start;
}



CalcFringe()

void CalcFringe(int iX, int iY)
{
if(iX < 0 || iX >= m_nMapWidth)
return;
if(iY < 0 || iY >= m_nMapHeight)
return;

bool bNeighbors[8];

POINT Start;
Start.x = iX;
Start.y = iY;

POINT Next;
for(unsigned int nDir = 0; nDir < 8; ++nDir)
{
Next = TileWalk(Start, nDir);
if(Next.x < 0 || Next.y < 0 || Next.x >= m_nMapWidth || Next.y >= m_nMapHeight)
bNeighbors[nDir] = 0;
else
{
unsigned int nTileNumber = m_pTiles[(Start.y * m_nMapWidth) + Start.x].m_nTileNumber;
if(nTileNumber == 0)
unsigned int nTileNumberB = m_pTiles[(Next.y * m_nMapWidth) + Next.x].m_nTileNumber;
if(m_pTiles[(Next.y * m_nMapWidth) + Next.x].m_nTileNumber > m_pTiles[(Start.y * m_nMapWidth) + Start.x].m_nTileNumber)
bNeighbors[nDir] = 1;
else
bNeighbors[nDir] = 0;
}
}

m_pTiles[(Start.y * m_nMapWidth) + Start.x].m_iFringe[UPPERLEFT] = (bNeighbors[6] + (2 * bNeighbors[7]) + (4 * bNeighbors[0]))|(bNeighbors[5] + (4 * bNeighbors[1]));
m_pTiles[(Start.y * m_nMapWidth) + Start.x].m_iFringe[UPPERRIGHT] = (bNeighbors[0] + (2 * bNeighbors[1]) + (4 * bNeighbors[2]))|(bNeighbors[7] + (4 * bNeighbors[3]));
m_pTiles[(Start.y * m_nMapWidth) + Start.x].m_iFringe[LOWERRIGHT] = (bNeighbors[2] + (2 * bNeighbors[3]) + (4 * bNeighbors[4]))|(bNeighbors[1] + (4 * bNeighbors[5]));
m_pTiles[(Start.y * m_nMapWidth) + Start.x].m_iFringe[LOWERLEFT] = (bNeighbors[4] + (2 * bNeighbors[5]) + (4 * bNeighbors[6]))|(bNeighbors[3] + (4 * bNeighbors[7]));

//dftcb::FormattedDebugOutput(__LINE__, __FILE__, "tile(%i, %i)
NORTH        %i
NORTHEAST        %i
EAST        %i
SOUTHEAST        %i
SOUTH        %i
SOUTHWEST        %i
WEST        %i
NORTHWEST        %i
", false, Start.x, Start.y, bNeighbors[0], bNeighbors[1], bNeighbors[2], bNeighbors[3], bNeighbors[4], bNeighbors[5], bNeighbors[6], bNeighbors[7], bNeighbors[8]);

}



DrawTile()

void DrawTile(dftgfx::VertexBuffer2* pBuffer, float fX, float fY, unsigned int nTileNumber)
{
fX = fX * TILE_WIDTH;
fY = fY * TILE_HEIGHT;

dftgfx::Vertex2* pVertices = 0;
pVertices = pBuffer->Lock(0, D3DLOCK_DISCARD);

pVertices[0].SetXY(fX, fY + TILE_HEIGHT);
pVertices[1].SetXY(fX, fY);
pVertices[2].SetXY(fX + TILE_WIDTH, fY + TILE_HEIGHT);
pVertices[3].SetXY(fX + TILE_WIDTH, fY);

float fU = (nTileNumber % 4) * TILE_WIDTH;
float fV = (nTileNumber / 4) * TILE_HEIGHT;
pVertices[0].SetUV(fU / TILESET_SIZE, (fV + TILE_HEIGHT) / TILESET_SIZE);
pVertices[1].SetUV(fU / TILESET_SIZE, fV / TILESET_SIZE);
pVertices[2].SetUV((fU + TILE_WIDTH) / TILESET_SIZE, (fV + TILE_HEIGHT) / TILESET_SIZE);
pVertices[3].SetUV((fU + TILE_WIDTH) / TILESET_SIZE, fV / TILESET_SIZE);

pVertices[0].SetDiffuse(0xffffffff);
pVertices[1].SetDiffuse(0xffffffff);
pVertices[2].SetDiffuse(0xffffffff);
pVertices[3].SetDiffuse(0xffffffff);

pBuffer->Unlock();
pBuffer->Draw(0, D3DPT_TRIANGLESTRIP, 0, 2);
}



Render()

void Render()
{
dftgfx::VertexBuffer2 Buffer;
Buffer.Create(4, D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT);
for(unsigned int nRow = 0; nRow < m_nMapHeight; ++nRow)
{
for(unsigned int nCol = 0; nCol < m_nMapWidth; ++nCol)
{
unsigned int nTile = m_pTiles[(nRow * m_nMapWidth) + nCol].m_nTileNumber;
dftgfx::TexturePool::GetSingleton()->SetTexture(0, m_TileSets[m_pTiles[(nRow * m_nMapWidth) + nCol].m_nTileSetID].m_nTextureID);
DrawTile(&Buffer, nCol, nRow, nTile);

dftgfx::TexturePool::GetSingleton()->SetTexture(0, m_TileSets[1].m_nTextureID);
unsigned int nIndex = (nRow * m_nMapWidth) + nCol;
int iULFringe = FringeLookUp[m_pTiles[nIndex].m_iFringe[UPPERLEFT]];
int iURFringe = FringeLookUp[m_pTiles[nIndex].m_iFringe[UPPERRIGHT]];
int iLRFringe = FringeLookUp[m_pTiles[nIndex].m_iFringe[LOWERRIGHT]];
int iLLFringe = FringeLookUp[m_pTiles[nIndex].m_iFringe[LOWERLEFT]];

//dftcb::FormattedDebugOutput(__LINE__, __FILE__, "tile(%i, %i)
{
UL: %i
UR: %i
LR: %i
LL: %i
}", false, nCol, nRow, iULFringe, iURFringe, iLRFringe, iLLFringe);


if(iULFringe >= 0)
DrawTile(&Buffer, nCol, nRow, iULFringe);
if(iURFringe >= 0)
DrawTile(&Buffer, nCol, nRow, iURFringe + 4);
if(iLRFringe >= 0)
DrawTile(&Buffer, nCol, nRow, iLRFringe + 8);
if(iLLFringe >= 0)
DrawTile(&Buffer, nCol, nRow, iLLFringe + 12);
}
}
Buffer.Release();
}

Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!