2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
// BiomeRenderer.cpp
|
|
|
|
|
|
|
|
// Implements the cBiomeRenderer class representing the rendering engine
|
|
|
|
|
|
|
|
#include "Globals.h"
|
|
|
|
#include "BiomeRenderer.h"
|
|
|
|
#include "Pixmap.h"
|
|
|
|
#include "Timer.h"
|
2013-11-24 11:49:04 -05:00
|
|
|
#include "BiomeColors.h"
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cBiomeRenderer::cBiomeRenderer(void) :
|
|
|
|
m_OriginX(160),
|
|
|
|
m_OriginY(160),
|
|
|
|
m_Zoom(1)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBiomeRenderer::SetSource(cBiomeSource * a_Source)
|
|
|
|
{
|
|
|
|
m_Cache.SetSource(a_Source);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cBiomeRenderer::Render(cPixmap & a_Pixmap)
|
|
|
|
{
|
|
|
|
cTimer Timer("cBiomeRenderer::Render");
|
|
|
|
|
|
|
|
int Wid = a_Pixmap.GetWidth();
|
|
|
|
int Hei = a_Pixmap.GetHeight();
|
|
|
|
|
|
|
|
// Hint the approximate view area to the biome source so that it can adjust its caches:
|
2014-01-10 05:55:43 -05:00
|
|
|
int MinBlockX = ( - m_OriginX) * m_Zoom;
|
|
|
|
int MaxBlockX = (Wid - m_OriginX) * m_Zoom;
|
|
|
|
int MinBlockZ = ( - m_OriginY) * m_Zoom;
|
|
|
|
int MaxBlockZ = (Hei - m_OriginY) * m_Zoom;
|
2013-07-29 07:13:03 -04:00
|
|
|
m_Cache.HintViewArea(MinBlockX / 16 - 1, MaxBlockX / 16 + 1, MinBlockZ / 16 - 1, MaxBlockZ / 16 + 1);
|
|
|
|
|
|
|
|
// Hold one current chunk of biome data:
|
|
|
|
int CurChunkX = -10000;
|
|
|
|
int CurChunkZ = -10000;
|
|
|
|
cChunkDef::BiomeMap CurBiomes;
|
|
|
|
|
|
|
|
bool res = false;
|
|
|
|
|
|
|
|
for (int y = 0; y < Hei; y++)
|
|
|
|
{
|
2014-01-10 05:55:43 -05:00
|
|
|
int BlockZ = (y - m_OriginY) * m_Zoom;
|
2013-07-29 07:13:03 -04:00
|
|
|
int ChunkZ = (BlockZ >= 0) ? (BlockZ / 16) : ((BlockZ + 1) / 16 - 1);
|
|
|
|
int RelZ = BlockZ - ChunkZ * 16;
|
|
|
|
for (int x = 0; x < Wid; x++)
|
|
|
|
{
|
2014-01-10 05:55:43 -05:00
|
|
|
int BlockX = (x - m_OriginX) * m_Zoom;
|
2013-07-29 07:13:03 -04:00
|
|
|
int ChunkX = (BlockX >= 0) ? (BlockX / 16) : ((BlockX + 1) / 16 - 1);
|
|
|
|
int RelX = BlockX - ChunkX * 16;
|
|
|
|
if ((ChunkZ != CurChunkZ) || (ChunkX != CurChunkX))
|
|
|
|
{
|
|
|
|
CurChunkX = ChunkX;
|
|
|
|
CurChunkZ = ChunkZ;
|
|
|
|
switch (m_Cache.GetBiome(CurChunkX, CurChunkZ, CurBiomes))
|
|
|
|
{
|
|
|
|
case cBiomeSource::baLater:
|
|
|
|
{
|
|
|
|
res = true;
|
|
|
|
// fallthrough:
|
|
|
|
}
|
|
|
|
case cBiomeSource::baNever:
|
|
|
|
{
|
|
|
|
for (int i = 0; i < ARRAYCOUNT(CurBiomes); i++)
|
|
|
|
{
|
2014-02-03 16:01:12 -05:00
|
|
|
CurBiomes[i] = biInvalidBiome;
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} // switch (Biome availability)
|
|
|
|
}
|
|
|
|
EMCSBiome Biome = cChunkDef::GetBiome(CurBiomes, RelX, RelZ);
|
|
|
|
a_Pixmap.SetPixel(x, y, GetBiomeColor(Biome));
|
|
|
|
} // for x
|
|
|
|
} // for y
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int cBiomeRenderer::GetBiomeColor(EMCSBiome a_Biome)
|
|
|
|
{
|
2013-11-24 11:49:04 -05:00
|
|
|
if ((a_Biome < 0) || (a_Biome >= ARRAYCOUNT(g_BiomeColors)))
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2013-11-24 11:49:04 -05:00
|
|
|
return 0xff0000;
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
2013-11-24 11:49:04 -05:00
|
|
|
return g_BiomeColors[a_Biome];
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cBiomeRenderer::MoveViewBy(int a_OffsX, int a_OffsY)
|
|
|
|
{
|
|
|
|
m_OriginX += a_OffsX;
|
|
|
|
m_OriginY += a_OffsY;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|