Started to rework tile checks, tile banks loading / saving. A tilebank will now be in the tilemodel, and it will work from there. Also moved some constants into an independent file.
--HG-- branch : gsoc2014-dfighterhg/feature/cdb-packed
parent
299629860b
commit
30bae94ac3
@ -0,0 +1,110 @@
|
||||
#include "tile_bank.h"
|
||||
#include "nel/3d/tile_bank.h"
|
||||
|
||||
#include <QPixmap>
|
||||
|
||||
bool pixmapToCBGRA( QPixmap &pixmap, std::vector< NLMISC::CBGRA >& pixels )
|
||||
{
|
||||
QImage img = pixmap.toImage();
|
||||
if( img.format() != QImage::Format_ARGB32 )
|
||||
img = img.convertToFormat( QImage::Format_ARGB32 );
|
||||
|
||||
if( img.format() != QImage::Format_ARGB32 )
|
||||
return false;
|
||||
|
||||
int c = img.width() * img.height();
|
||||
|
||||
const unsigned char *data = img.bits();
|
||||
const unsigned int *idata = reinterpret_cast< const unsigned int* >( data );
|
||||
|
||||
NLMISC::CBGRA bgra;
|
||||
pixels.clear();
|
||||
|
||||
int i = 0;
|
||||
while( i < c )
|
||||
{
|
||||
bgra.A = ( idata[ i ] & 0xFF000000 ) >> 24;
|
||||
bgra.R = ( idata[ i ] & 0x00FF0000 ) >> 16;
|
||||
bgra.G = ( idata[ i ] & 0x0000FF00 ) >> 8;
|
||||
bgra.B = ( idata[ i ] & 0x000000FF );
|
||||
pixels.push_back( bgra );
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
class TileBankPvt
|
||||
{
|
||||
public:
|
||||
NL3D::CTileBank m_bank;
|
||||
};
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TileBank::TileBank()
|
||||
{
|
||||
m_pvt = new TileBankPvt();
|
||||
}
|
||||
|
||||
TileBank::~TileBank()
|
||||
{
|
||||
delete m_pvt;
|
||||
}
|
||||
|
||||
void TileBank::addTileSet( const QString &name )
|
||||
{
|
||||
m_pvt->m_bank.addTileSet( name.toUtf8().constData() );
|
||||
NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( 0 );
|
||||
}
|
||||
|
||||
void TileBank::addLand( const QString &name )
|
||||
{
|
||||
m_pvt->m_bank.addLand( name.toUtf8().constData() );
|
||||
}
|
||||
|
||||
void TileBank::setLandSets( int idx, const QStringList &l )
|
||||
{
|
||||
NL3D::CTileLand *land = m_pvt->m_bank.getLand( idx );
|
||||
land->clear();
|
||||
|
||||
QStringListIterator itr( l );
|
||||
while( itr.hasNext() )
|
||||
{
|
||||
land->addTileSet( itr.next().toUtf8().constData() );
|
||||
}
|
||||
}
|
||||
|
||||
bool TileBank::addTileToSet( int idx, const QString &name, const QVariant &pixmap, TileConstants::TTileChannel channel, TileConstants::TNodeTileType type )
|
||||
{
|
||||
NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( idx );
|
||||
if( set == NULL )
|
||||
return false;
|
||||
|
||||
QPixmap pm = pixmap.value< QPixmap >();
|
||||
if( pm.isNull() )
|
||||
return false;
|
||||
|
||||
if( pm.width() != pm.height() )
|
||||
return false;
|
||||
|
||||
std::vector< NLMISC::CBGRA > pixels;
|
||||
pixmapToCBGRA( pm, pixels );
|
||||
|
||||
int tile;
|
||||
set->addTile128( tile, m_pvt->m_bank );
|
||||
|
||||
NL3D::CTileBorder border;
|
||||
border.set( pm.width(), pm.height(), pixels );
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
#ifndef TILE_BANK_H
|
||||
#define TILE_BANK_H
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QVariant>
|
||||
|
||||
#include "tile_constants.h"
|
||||
|
||||
class TileBankPvt;
|
||||
|
||||
class TileBank
|
||||
{
|
||||
public:
|
||||
TileBank();
|
||||
~TileBank();
|
||||
|
||||
void addTileSet( const QString &name );
|
||||
void addLand( const QString &name );
|
||||
void setLandSets( int idx, const QStringList &l );
|
||||
|
||||
bool addTileToSet( int idx, const QString &name, const QVariant &pixmap, TileConstants::TTileChannel channel, TileConstants::TNodeTileType type );
|
||||
|
||||
private:
|
||||
TileBankPvt *m_pvt;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -0,0 +1,26 @@
|
||||
#ifndef TILE_CONSTANTS_H
|
||||
#define TILE_CONSTANTS_H
|
||||
|
||||
|
||||
namespace TileConstants
|
||||
{
|
||||
enum TTileChannel
|
||||
{
|
||||
TileDiffuse = 0,
|
||||
TileAdditive = 1,
|
||||
TileAlpha = 2,
|
||||
TileChannelCount = 3
|
||||
};
|
||||
|
||||
enum TNodeTileType
|
||||
{
|
||||
Tile128 = 0,
|
||||
Tile256 = 1,
|
||||
TileTransition = 2,
|
||||
TileDisplacement = 3,
|
||||
TileNodeTypeCount = 4
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue