Merge with develop

This commit is contained in:
kervala 2016-01-05 13:00:18 +01:00
parent e5a1249cb8
commit d46d1e45ad
9 changed files with 109 additions and 49 deletions

View file

@ -271,7 +271,6 @@ void CPSUtil::displayBasis(IDriver *driver, const CMatrix &modelMat, const NLMIS
void CPSUtil::print(IDriver *driver, const std::string &text, CFontGenerator &fg, CFontManager &fm, const CVector &pos, float size, NLMISC::CRGBA col /*= NLMISC::CRGBA::White*/)
{
NL_PS_FUNC(CPSUtil_print)
nlassert((&fg) && (&fm));
CComputedString cptedString;
fm.computeString ( text,
&fg,

View file

@ -1537,7 +1537,7 @@ namespace NLGUI
for (uint e=0 ; e<__num__ ; e++) \
{ \
std::string str = __toStringFunc__((__enum__)e); \
std::string temp = __name__ + toString(".") + __toStringFunc__((__enum__)e) + " = " + toString("%d;", e); \
std::string temp = __name__ + toString(".") + __toStringFunc__((__enum__)e) + " = " + toString("%u;", e); \
ls.executeScript(temp); \
} \

View file

@ -268,7 +268,11 @@ int main(int nNbArg, char **ppArgs)
uint8 colors = pBtmp->load(inFile);
if (colors != 32) throw NLMISC::Exception(AllMapNames[i] + " is using " + toString(colors) + " bits colors, only 32 bit supported!");
if (pBtmp->getPixelFormat() != CBitmap::RGBA)
{
nlwarning("Converting %s to RGBA (32 bits), originally using %u bits...", AllMapNames[i].c_str(), (uint)colors);
pBtmp->convertToType(CBitmap::RGBA);
}
AllMaps[i] = pBtmp;
}

View file

@ -670,8 +670,8 @@ static void BuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::str
{
uint8 value = 0;
// texture can be converted if all alphas are 0 or 255
if (srcBitmap.isAlphaUniform(&value) && (value == 255 || value == 0))
// texture can be converted if all alphas are 255
if (srcBitmap.isAlphaUniform(&value) && value == 255)
{
if (bi.OptimizeTextures > 1)
{

View file

@ -29,8 +29,10 @@ void writeInstructions()
std::cout << " By default, it only make checks and display if texture can optimized or not" << std::endl;
std::cout << std::endl;
std::cout << "with" << std::endl;
std::cout << "-a : Remove alpha channel if useless" << std::endl;
std::cout << "-a : Remove alpha channel if useless (255)" << std::endl;
std::cout << "-g : Convert to grayscale if all pixels are gray" << std::endl;
std::cout << "-t : Apply texture optimizations (same as -a -g)" << std::endl;
std::cout << "-m : Apply mask optimizations (convert to grayscale using red value and remove alpha)" << std::endl;
std::cout << std::endl;
std::cout << "-h or -? for this help" << std::endl;
std::cout << std::endl;
@ -38,6 +40,8 @@ void writeInstructions()
bool FixAlpha = false;
bool FixGrayscale = false;
bool TextureOptimizations = false;
bool MaskOptimizations = false;
std::vector<std::string> InputFilenames;
@ -74,6 +78,18 @@ bool parseOptions(int argc, char **argv)
{
FixGrayscale = true;
}
// Texture optimizations
else if (option == "t")
{
TextureOptimizations = true;
FixAlpha = true;
FixGrayscale = true;
}
// Mask optimizations
else if (option == "m")
{
MaskOptimizations = true;
}
else if (option == "h" || option == "?")
{
return false;
@ -168,35 +184,74 @@ int main(int argc, char **argv)
isGrayscale = true;
}
if (!isGrayscale && bitmap.isGrayscale())
if (MaskOptimizations && (!isGrayscale || hasAlpha))
{
std::cout << InputFilenames[i] << " (grayscale image with RGB colors)" << std::endl;
std::cout << InputFilenames[i] << " (mask with wrong format)" << std::endl;
if (FixGrayscale)
if (!isGrayscale)
{
if (!bitmap.convertToType(hasAlpha ? NLMISC::CBitmap::AlphaLuminance:NLMISC::CBitmap::Luminance))
// get a pointer on original RGBA data
uint32 size = bitmap.getPixels().size();
uint32 *data = (uint32*)bitmap.getPixels().getPtr();
uint32 *endData = (uint32*)((uint8*)data + size);
NLMISC::CRGBA *color = NULL;
// process all pixels
while(data < endData)
{
std::cerr << "Unable to convert to Luminance" << std::endl;
return 1;
color = (NLMISC::CRGBA*)data;
// copy red value to green and blue,
// because only red is used for mask
color->B = color->G = color->R;
// make opaque
color->A = 255;
++data;
}
isGrayscale = true;
modified = true;
}
// already in grayscale, just remove alpha
bitmap.convertToType(NLMISC::CBitmap::Luminance);
isGrayscale = true;
hasAlpha = false;
modified = true;
}
uint8 alpha = 0;
if (hasAlpha && bitmap.isAlphaUniform(&alpha))
else
{
std::cout << InputFilenames[i] << " (image with uniform alpha channel " << (sint)alpha << ")" << std::endl;
if (FixAlpha && (alpha == 0 || alpha == 255))
if (!isGrayscale && bitmap.isGrayscale())
{
bitmap.makeOpaque();
std::cout << InputFilenames[i] << " (grayscale image with RGB colors)" << std::endl;
hasAlpha = false;
modified = true;
if (FixGrayscale)
{
if (!bitmap.convertToType(hasAlpha ? NLMISC::CBitmap::AlphaLuminance:NLMISC::CBitmap::Luminance))
{
std::cerr << "Unable to convert to Luminance" << std::endl;
return 1;
}
isGrayscale = true;
modified = true;
}
}
uint8 alpha = 0;
if (hasAlpha && bitmap.isAlphaUniform(&alpha))
{
std::cout << InputFilenames[i] << " (image with uniform alpha channel " << (sint)alpha << ")" << std::endl;
if (FixAlpha && alpha == 255)
{
bitmap.makeOpaque();
hasAlpha = false;
modified = true;
}
}
}

View file

@ -49,6 +49,7 @@
#include <nel/3d/material.h>
#include <math.h>
#include <limits>
using namespace NLMISC;
using namespace NL3D;
@ -70,8 +71,8 @@ UMaterial sceneMaterial;
namespace R2
{
const TBufferEntry InteriorValue= (TBufferEntry)(~0u-1);
const TBufferEntry ValueBorder= (TBufferEntry)(~0u-2);
const TBufferEntry InteriorValue = std::numeric_limits<TBufferEntry>::max()-1;
const TBufferEntry ValueBorder = std::numeric_limits<TBufferEntry>::max()-2;
const uint32 BigValue= 15*5;
const float limitValue = 200.0;
@ -1957,7 +1958,7 @@ void CProximityMapBuffer::load(const std::string& name)
}
}
// setup the next pixel in the output buffers...
_Buffer[y*_ScanWidth+x]= (isAccessible? 0: (TBufferEntry)~0u);
_Buffer[y*_ScanWidth+x]= (isAccessible? 0:std::numeric_limits<TBufferEntry>::max());
}
}
}
@ -2044,7 +2045,7 @@ void CProximityMapBuffer::_prepareBufferForZoneProximityMap(const CProximityZone
uint32 zoneWidth= zone.getZoneWidth();
uint32 zoneHeight= zone.getZoneHeight();
zoneBuffer.clear();
zoneBuffer.resize(zoneWidth*zoneHeight,(TBufferEntry)~0u);
zoneBuffer.resize(zoneWidth*zoneHeight, std::numeric_limits<TBufferEntry>::max());
// setup the buffer's accessible points and prime vects[0] with the set of accessible points in the zone buffer
for (uint32 i=0;i<zone.getOffsets().size();++i)
@ -2073,11 +2074,11 @@ void CProximityMapBuffer::_prepareBufferForZoneProximityMap(const CProximityZone
{
zoneBuffer[offset]= InteriorValue;
if(offset-1>=startOffset && zoneBuffer[offset-1]==(TBufferEntry)~0u)
if(offset-1>=startOffset && zoneBuffer[offset-1] == std::numeric_limits<TBufferEntry>::max())
{
zoneBuffer[offset-1] = ValueBorder;
}
if(offset+1<=endOffset && zoneBuffer[offset+1]==(TBufferEntry)~0u)
if(offset+1<=endOffset && zoneBuffer[offset+1] == std::numeric_limits<TBufferEntry>::max())
{
zoneBuffer[offset+1] = ValueBorder;
}
@ -2105,11 +2106,11 @@ void CProximityMapBuffer::_prepareBufferForZoneProximityMap(const CProximityZone
{
zoneBuffer[offset]= InteriorValue;
if(offset>zoneWidth && zoneBuffer[offset-zoneWidth]==(TBufferEntry)~0u)
if(offset>zoneWidth && zoneBuffer[offset-zoneWidth] == std::numeric_limits<TBufferEntry>::max())
{
zoneBuffer[offset-zoneWidth] = ValueBorder;
}
if(offset+zoneWidth<zoneHeight*zoneWidth && zoneBuffer[offset+zoneWidth]==(TBufferEntry)~0u)
if(offset+zoneWidth<zoneHeight*zoneWidth && zoneBuffer[offset+zoneWidth] == std::numeric_limits<TBufferEntry>::max())
{
zoneBuffer[offset+zoneWidth] = ValueBorder;
}
@ -2154,19 +2155,19 @@ void CProximityMapBuffer::generateZoneProximityMap(const CProximityZone& zone,TB
zoneBuffer[val]=dist;
// decompose into x and y in order to manage identification of neighbour cells correctly
uint32 x= val% zoneWidth;
uint32 y= val/ zoneWidth;
uint32 x= val % zoneWidth;
uint32 y= val / zoneWidth;
#define TEST_MOVE(xoffs,yoffs,newDist)\
{\
if (((uint32)(x+(xoffs))<zoneWidth) && ((uint32)(y+(yoffs))<zoneHeight))\
if (((uint32)(x+xoffs)<zoneWidth) && ((uint32)(y+yoffs)<zoneHeight))\
{\
uint32 newVal= val+(xoffs)+((yoffs)*zoneWidth);\
bool isInterior= ((zoneBuffer[newVal]==InteriorValue && newDist > BigValue) || (zoneBuffer[newVal]==ValueBorder && newDist > BigValue));\
if (zoneBuffer[newVal]>(newDist) && !isInterior)\
uint32 newVal= val+xoffs+(yoffs*zoneWidth);\
bool isInterior = ((zoneBuffer[newVal] == InteriorValue && newDist > BigValue) || (zoneBuffer[newVal] == ValueBorder && newDist > BigValue));\
if (zoneBuffer[newVal] > newDist && !isInterior)\
{\
zoneBuffer[newVal]=(newDist);\
vects[(newDist)&15].push_back(newVal);\
zoneBuffer[newVal] = newDist;\
vects[newDist & 15].push_back(newVal);\
++entriesToTreat;\
}\
}\
@ -2239,8 +2240,8 @@ CProximityZone::CProximityZone(uint32 scanWidth,uint32 scanHeight,sint32 xOffset
_MaxOffset = scanWidth * scanHeight -1;
_XMin = ~0u;
_YMin = ~0u;
_XMin = std::numeric_limits<uint32>::max();
_YMin = std::numeric_limits<uint32>::max();
_XMax = 0;
_YMax = 0;

View file

@ -190,8 +190,9 @@ public:
TParamInfo(const std::string &name, STRING_MANAGER::TParamType type, const std::string &compilerParam = "")
: ParamName(name),
ParamType(type),
CompilerParam(compilerParam)
CompilerParam(compilerParam),
ParamType(type)
{
}
};
@ -328,7 +329,7 @@ private:
std::string genPreRequisites();
// forbidden copy constructor !
CMissionData(const CMissionData &other)
CMissionData(const CMissionData &other):NLMISC::CRefCount()
{
nlstop;
}

View file

@ -255,8 +255,8 @@ public:
CStepObjective(CMissionData &md, IPrimitive *prim, const std::string &prefix = "")
: CStep(md, prim),
_HideObj(false),
_Prefix(prefix)
_Prefix(prefix),
_HideObj(false)
{
}

View file

@ -206,7 +206,7 @@ void extractNewWords(string workSheetFileName, string columnId, IWordListBuilder
return;
}
// get the name column index
uint nameColIndex;
uint nameColIndex = 0;
if(!workSheet.findCol(ucstring("name"), nameColIndex))
{
nlwarning("Error: Don't find the column 'name'. '%s' Aborted", workSheetFileName.c_str());