mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-22 23:06:18 +00:00
Merge with develop
This commit is contained in:
parent
fc903ff30c
commit
db718f9a40
1 changed files with 91 additions and 129 deletions
|
@ -24,8 +24,7 @@
|
||||||
#include "nel/misc/log.h"
|
#include "nel/misc/log.h"
|
||||||
#include "nel/misc/path.h"
|
#include "nel/misc/path.h"
|
||||||
#include "nel/misc/uv.h"
|
#include "nel/misc/uv.h"
|
||||||
|
#include "nel/misc/cmd_args.h"
|
||||||
//#include "windows.h"
|
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -36,21 +35,9 @@ using namespace std;
|
||||||
using namespace NLMISC;
|
using namespace NLMISC;
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
//char sExeDir[MAX_PATH];
|
void outString(const string &sText)
|
||||||
std::string sExeDir;
|
|
||||||
NLMISC::CApplicationContext _ApplicationContext;
|
|
||||||
|
|
||||||
void outString (const string &sText)
|
|
||||||
{
|
{
|
||||||
std::string sCurDir = CPath::getCurrentPath();
|
printf("%s\n", sText.c_str());
|
||||||
CPath::setCurrentPath(sExeDir.c_str());
|
|
||||||
//char sCurDir[MAX_PATH];
|
|
||||||
//GetCurrentDirectory (MAX_PATH, sCurDir);
|
|
||||||
//SetCurrentDirectory (sExeDir);
|
|
||||||
NLMISC::createDebug ();
|
|
||||||
NLMISC::InfoLog->displayRaw(sText.c_str());
|
|
||||||
//SetCurrentDirectory (sCurDir);
|
|
||||||
CPath::setCurrentPath(sCurDir.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
|
@ -59,7 +46,7 @@ const uint32 posStep= 4;
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
// Try all position to put pSrc in pDst
|
// Try all position to put pSrc in pDst
|
||||||
bool tryAllPos (NLMISC::CBitmap *pSrc, NLMISC::CBitmap *pDst, sint32 &x, sint32 &y)
|
bool tryAllPos(NLMISC::CBitmap *pSrc, NLMISC::CBitmap *pDst, sint32 &x, sint32 &y)
|
||||||
{
|
{
|
||||||
uint32 i, j;
|
uint32 i, j;
|
||||||
CObjectVector<uint8> &rSrcPix = pSrc->getPixels();
|
CObjectVector<uint8> &rSrcPix = pSrc->getPixels();
|
||||||
|
@ -111,7 +98,7 @@ void putPixel(uint8 *dst, uint8 *src, bool alphaTransfert)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
bool putIn (NLMISC::CBitmap *pSrc, NLMISC::CBitmap *pDst, sint32 x, sint32 y, bool alphaTransfert=true)
|
bool putIn(NLMISC::CBitmap *pSrc, NLMISC::CBitmap *pDst, sint32 x, sint32 y, bool alphaTransfert=true)
|
||||||
{
|
{
|
||||||
uint8 *rSrcPix = &pSrc->getPixels()[0];
|
uint8 *rSrcPix = &pSrc->getPixels()[0];
|
||||||
uint8 *rDstPix = &pDst->getPixels()[0];
|
uint8 *rDstPix = &pDst->getPixels()[0];
|
||||||
|
@ -158,18 +145,17 @@ bool putIn (NLMISC::CBitmap *pSrc, NLMISC::CBitmap *pDst, sint32 x, sint32 y, bo
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
string getBaseName (const string &fullname)
|
string getBaseName(const string &fullname)
|
||||||
{
|
{
|
||||||
string sTmp2;
|
string basename;
|
||||||
string::size_type pos = fullname.rfind('_');
|
string::size_type pos = fullname.rfind('_');
|
||||||
if (pos != string::npos)
|
if (pos != string::npos) basename = fullname.substr(0, pos+1);
|
||||||
sTmp2 = fullname.substr(0, pos+1);
|
return basename;
|
||||||
return sTmp2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
// resize the bitmap to the next power of 2 and preserve content
|
// resize the bitmap to the next power of 2 and preserve content
|
||||||
void enlargeCanvas (NLMISC::CBitmap &b)
|
void enlargeCanvas(NLMISC::CBitmap &b)
|
||||||
{
|
{
|
||||||
sint32 nNewWidth = b.getWidth(), nNewHeight = b.getHeight();
|
sint32 nNewWidth = b.getWidth(), nNewHeight = b.getHeight();
|
||||||
if (nNewWidth > nNewHeight)
|
if (nNewWidth > nNewHeight)
|
||||||
|
@ -188,65 +174,77 @@ void enlargeCanvas (NLMISC::CBitmap &b)
|
||||||
b = b2;
|
b = b2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool writeFileDependingOnFilename(const std::string &filename, CBitmap &bitmap)
|
||||||
|
{
|
||||||
|
NLMISC::COFile out;
|
||||||
|
|
||||||
|
if (out.open(filename))
|
||||||
|
{
|
||||||
|
if (toLower(filename).find(".png") != string::npos)
|
||||||
|
{
|
||||||
|
bitmap.writePNG(out, 32);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bitmap.writeTGA(out, 32);
|
||||||
|
}
|
||||||
|
|
||||||
|
out.close();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
// main
|
// main
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
int main(int nNbArg, char **ppArgs)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
//GetCurrentDirectory (MAX_PATH, sExeDir);
|
CApplicationContext applicationContext;
|
||||||
sExeDir = CPath::getCurrentPath();
|
|
||||||
|
|
||||||
if (nNbArg < 3)
|
// Parse Command Line.
|
||||||
{
|
NLMISC::CCmdArgs args;
|
||||||
outString ("ERROR : Wrong number of arguments\n");
|
|
||||||
outString ("USAGE : build_interface [-s<existing_uv_txt_name>] <out_tga_name> <path_maps1> [path_maps2] [path_maps3] ....\n");
|
args.setDescription("Build a huge interface texture from several small elements to optimize video memory usage.");
|
||||||
outString (" -s : build a subset of an existing interface definition while preserving the existing texture ids,");
|
args.addArg("s", "subset", "existing_uv_txt_name", "Build a subset of an existing interface definition while preserving the existing texture ids, to support freeing up VRAM by switching to the subset without rebuilding the entire interface.");
|
||||||
outString (" to support freeing up VRAM by switching to the subset without rebuilding the entire interface\n");
|
args.addAdditionalArg("output_filename", "PNG or TGA file to generate", true);
|
||||||
return -1;
|
args.addAdditionalArg("input_path", "Path that containts interfaces elements", false);
|
||||||
}
|
|
||||||
|
if (!args.parse(argc, argv)) return 1;
|
||||||
|
|
||||||
// build as a subset of existing interface
|
// build as a subset of existing interface
|
||||||
bool buildSubset = false;
|
bool buildSubset = false;
|
||||||
string existingUVfilename;
|
string existingUVfilename;
|
||||||
list<string> inputDirs;
|
|
||||||
for ( uint i=1; (sint)i<nNbArg; ++i )
|
if (args.haveArg("s"))
|
||||||
{
|
{
|
||||||
if ( ppArgs[i][0] == '-' )
|
|
||||||
{
|
|
||||||
switch ( ppArgs[i][1] )
|
|
||||||
{
|
|
||||||
case 'S':
|
|
||||||
case 's':
|
|
||||||
buildSubset = true;
|
buildSubset = true;
|
||||||
existingUVfilename = string( ppArgs[i]+2 );
|
existingUVfilename = args.getArg("s").front();
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
inputDirs.push_back(ppArgs[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string fmtName;
|
std::vector<std::string> inputDirs = args.getAdditionalArg("input_path");
|
||||||
uint iNumDirs = (uint)inputDirs.size();
|
|
||||||
if( iNumDirs )
|
string fmtName = args.getAdditionalArg("output_filename").front();
|
||||||
{
|
|
||||||
fmtName = inputDirs.front();
|
// append PNG extension if no one provided
|
||||||
inputDirs.pop_front();
|
if (fmtName.rfind('.') == string::npos) fmtName += ".png";
|
||||||
--iNumDirs;
|
|
||||||
}
|
|
||||||
vector<string> AllMapNames;
|
vector<string> AllMapNames;
|
||||||
list<string>::iterator it = inputDirs.begin();
|
vector<string>::iterator it = inputDirs.begin(), itEnd = inputDirs.end();
|
||||||
list<string>::iterator itEnd = inputDirs.end();
|
|
||||||
while( it != itEnd )
|
while( it != itEnd )
|
||||||
{
|
{
|
||||||
string sDir = *it++;
|
string sDir = *it++;
|
||||||
|
|
||||||
if( !CFile::isDirectory(sDir) )
|
if( !CFile::isDirectory(sDir) )
|
||||||
{
|
{
|
||||||
outString (string("ERROR : directory ") + sDir + " does not exist\n");
|
outString(toString("ERROR: directory %s does not exist", sDir.c_str()));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
CPath::getPathContent(sDir, false, false, true, AllMapNames);
|
CPath::getPathContent(sDir, false, false, true, AllMapNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,13 +262,14 @@ int main(int nNbArg, char **ppArgs)
|
||||||
{
|
{
|
||||||
pBtmp = new NLMISC::CBitmap;
|
pBtmp = new NLMISC::CBitmap;
|
||||||
NLMISC::CIFile inFile;
|
NLMISC::CIFile inFile;
|
||||||
if (!inFile.open( AllMapNames[i] )) throw NLMISC::Exception("Unable to open " + AllMapNames[i]);
|
|
||||||
|
if (!inFile.open(AllMapNames[i])) throw NLMISC::Exception("Unable to open " + AllMapNames[i]);
|
||||||
|
|
||||||
uint8 colors = pBtmp->load(inFile);
|
uint8 colors = pBtmp->load(inFile);
|
||||||
|
|
||||||
if (pBtmp->getPixelFormat() != CBitmap::RGBA)
|
if (pBtmp->getPixelFormat() != CBitmap::RGBA)
|
||||||
{
|
{
|
||||||
nlwarning("Converting %s to RGBA (32 bits), originally using %u bits...", AllMapNames[i].c_str(), (uint)colors);
|
outString(toString("Converting %s to RGBA (32 bits), originally using %u bits...", AllMapNames[i].c_str(), (uint)colors));
|
||||||
pBtmp->convertToType(CBitmap::RGBA);
|
pBtmp->convertToType(CBitmap::RGBA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,7 +279,7 @@ int main(int nNbArg, char **ppArgs)
|
||||||
{
|
{
|
||||||
if (pBtmp) delete pBtmp;
|
if (pBtmp) delete pBtmp;
|
||||||
|
|
||||||
outString (string("ERROR :") + e.what());
|
outString(toString("ERROR : %s", e.what()));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -314,6 +313,7 @@ int main(int nNbArg, char **ppArgs)
|
||||||
vector<NLMISC::CUV> UVMin, UVMax;
|
vector<NLMISC::CUV> UVMin, UVMax;
|
||||||
UVMin.resize (mapSize, NLMISC::CUV(0.0f, 0.0f));
|
UVMin.resize (mapSize, NLMISC::CUV(0.0f, 0.0f));
|
||||||
UVMax.resize (mapSize, NLMISC::CUV(0.0f, 0.0f));
|
UVMax.resize (mapSize, NLMISC::CUV(0.0f, 0.0f));
|
||||||
|
|
||||||
for (sint i = 0; i < mapSize; ++i)
|
for (sint i = 0; i < mapSize; ++i)
|
||||||
{
|
{
|
||||||
sint32 x, y;
|
sint32 x, y;
|
||||||
|
@ -323,40 +323,20 @@ int main(int nNbArg, char **ppArgs)
|
||||||
enlargeCanvas (GlobalTexture);
|
enlargeCanvas (GlobalTexture);
|
||||||
enlargeCanvas (GlobalMask);
|
enlargeCanvas (GlobalMask);
|
||||||
}
|
}
|
||||||
|
|
||||||
putIn (AllMaps[i], &GlobalTexture, x, y);
|
putIn (AllMaps[i], &GlobalTexture, x, y);
|
||||||
putIn (AllMaps[i], &GlobalMask, x, y, false);
|
putIn (AllMaps[i], &GlobalMask, x, y, false);
|
||||||
|
|
||||||
UVMin[i].U = (float)x;
|
UVMin[i].U = (float)x;
|
||||||
UVMin[i].V = (float)y;
|
UVMin[i].V = (float)y;
|
||||||
UVMax[i].U = (float)x+AllMaps[i]->getWidth();
|
UVMax[i].U = (float)x+AllMaps[i]->getWidth();
|
||||||
UVMax[i].V = (float)y+AllMaps[i]->getHeight();
|
UVMax[i].V = (float)y+AllMaps[i]->getHeight();
|
||||||
|
|
||||||
/* // Do not remove this is useful for debugging
|
#if 0
|
||||||
{
|
// Do not remove this is useful for debugging
|
||||||
NLMISC::COFile outTga;
|
writeFileDependingOnFilename(fmtName.substr(0, fmtName.rfind('.')) + "_txt.png", GlobalTexture);
|
||||||
string fmtName = ppArgs[1];
|
writeFileDependingOnFilename(fmtName.substr(0, fmtName.rfind('.')) + "_msk.png", GlobalMask);
|
||||||
if (fmtName.rfind('.') == string::npos)
|
#endif
|
||||||
fmtName += ".tga";
|
|
||||||
if (outTga.open(fmtName))
|
|
||||||
{
|
|
||||||
GlobalTexture.writeTGA (outTga, 32);
|
|
||||||
outTga.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
NLMISC::COFile outTga;
|
|
||||||
string fmtName = ppArgs[1];
|
|
||||||
if (fmtName.rfind('.') == string::npos)
|
|
||||||
fmtName += "_msk.tga";
|
|
||||||
else
|
|
||||||
fmtName = fmtName.substr(0,fmtName.rfind('.')) + "_msk.tga";
|
|
||||||
if (outTga.open(fmtName))
|
|
||||||
{
|
|
||||||
GlobalMask.writeTGA (outTga, 32);
|
|
||||||
outTga.close();
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert UV from pixel to ratio
|
// Convert UV from pixel to ratio
|
||||||
|
@ -369,32 +349,13 @@ int main(int nNbArg, char **ppArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write global texture file
|
// Write global texture file
|
||||||
//SetCurrentDirectory (sExeDir);
|
if (writeFileDependingOnFilename(fmtName, GlobalTexture))
|
||||||
CPath::setCurrentPath(sExeDir.c_str());
|
|
||||||
|
|
||||||
NLMISC::COFile outTga;
|
|
||||||
if (fmtName.rfind('.') == string::npos)
|
|
||||||
fmtName += ".tga";
|
|
||||||
if (outTga.open(fmtName))
|
|
||||||
{
|
{
|
||||||
std::string ext;
|
outString(toString("Writing %s", fmtName.c_str()));
|
||||||
if (toLower(fmtName).find(".png") != string::npos)
|
|
||||||
{
|
|
||||||
ext = "png";
|
|
||||||
GlobalTexture.writePNG (outTga, 32);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ext = "tga";
|
outString(toString("ERROR: Unable to write %s", fmtName.c_str()));
|
||||||
GlobalTexture.writeTGA (outTga, 32);
|
|
||||||
}
|
|
||||||
|
|
||||||
outTga.close();
|
|
||||||
outString (toString("Writing %s file : %s\n", ext.c_str(), fmtName.c_str()));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
outString (string("ERROR: Cannot write tga file : ") + fmtName + "\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write UV text file
|
// Write UV text file
|
||||||
|
@ -402,22 +363,23 @@ int main(int nNbArg, char **ppArgs)
|
||||||
{
|
{
|
||||||
fmtName = fmtName.substr(0, fmtName.rfind('.'));
|
fmtName = fmtName.substr(0, fmtName.rfind('.'));
|
||||||
fmtName += ".txt";
|
fmtName += ".txt";
|
||||||
FILE *f = fopen (fmtName.c_str(), "wt");
|
FILE *f = nlfopen(fmtName, "wt");
|
||||||
if (f != NULL)
|
if (f != NULL)
|
||||||
{
|
{
|
||||||
for (sint i = 0; i < mapSize; ++i)
|
for (sint i = 0; i < mapSize; ++i)
|
||||||
{
|
{
|
||||||
// get the string whitout path
|
// get the string whitout path
|
||||||
string fileName= CFile::getFilename(AllMapNames[i]);
|
string fileName = CFile::getFilename(AllMapNames[i]);
|
||||||
fprintf (f, "%s %.12f %.12f %.12f %.12f\n", fileName.c_str(), UVMin[i].U, UVMin[i].V,
|
fprintf (f, "%s %.12f %.12f %.12f %.12f\n", fileName.c_str(), UVMin[i].U, UVMin[i].V, UVMax[i].U, UVMax[i].V);
|
||||||
UVMax[i].U, UVMax[i].V);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose (f);
|
fclose (f);
|
||||||
outString (string("Writing UV file : ") + fmtName + "\n");
|
|
||||||
|
outString(toString("Writing UV file %s", fmtName.c_str()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
outString (string("ERROR: Cannot write UV file : ") + fmtName + "\n");
|
outString(toString("ERROR: Cannot write UV file %s", fmtName.c_str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // build as a subset
|
else // build as a subset
|
||||||
|
@ -425,20 +387,21 @@ int main(int nNbArg, char **ppArgs)
|
||||||
// Load existing uv file
|
// Load existing uv file
|
||||||
CIFile iFile;
|
CIFile iFile;
|
||||||
string filename = CPath::lookup (existingUVfilename, false);
|
string filename = CPath::lookup (existingUVfilename, false);
|
||||||
if( (filename == "") || (!iFile.open(filename)) )
|
|
||||||
|
if( filename.empty() || !iFile.open(filename) )
|
||||||
{
|
{
|
||||||
outString (string("ERROR : could not open file ") + existingUVfilename + "\n");
|
outString(toString("ERROR: Unable to open %s", existingUVfilename.c_str()));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write subset UV text file
|
// Write subset UV text file
|
||||||
fmtName = fmtName.substr(0, fmtName.rfind('.'));
|
fmtName = fmtName.substr(0, fmtName.rfind('.'));
|
||||||
fmtName += ".txt";
|
fmtName += ".txt";
|
||||||
FILE *f = fopen (fmtName.c_str(), "wt");
|
FILE *f = nlfopen(fmtName, "wt");
|
||||||
|
|
||||||
if (f == NULL)
|
if (f == NULL)
|
||||||
{
|
{
|
||||||
outString (string("ERROR: Cannot write UV file : ") + fmtName + "\n");
|
outString(toString("ERROR: Unable to write UV file %s", fmtName.c_str()));
|
||||||
// fclose (iFile);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -478,9 +441,8 @@ int main(int nNbArg, char **ppArgs)
|
||||||
UVMax[i].U, UVMax[i].V);
|
UVMax[i].U, UVMax[i].V);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// fclose (iFile);
|
|
||||||
fclose (f);
|
fclose (f);
|
||||||
outString (string("Writing UV file : ") + fmtName + "\n");
|
outString(toString("Writing UV file: %s", fmtName.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue