📄 tileassembler.cpp
字号:
/*
* Copyright (C) 2005,2006,2007 MaNGOS <http://www.mangosproject.org/>
* Copyright (C) 2007-2008 Ascent Team <http://www.ascentemu.com/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <G3D/Vector3.h>
#include <G3D/Triangle.h>
#include "TileAssembler.h"
#include "CoordModelMapping.h"
#include "ModelContainer.h"
#include <string.h>
//gcc 4.3 fix
#include <limits.h>
#ifdef _ASSEMBLER_DEBUG
FILE *g_df = NULL;
#endif
namespace VMAP
{
//=================================================================
Vector3 ModelPosition::transform(const Vector3& pIn) const
{
//return(pIn);
Vector3 out = pIn * iScale;
out = izMatrix * out;
out = ixMatrix * out;
out = iyMatrix * out;
return(out);
}
//=================================================================
TileAssembler::TileAssembler(const std::string& pSrcDirName, const std::string& pDestDirName)
{
iCurrentUniqueNameId = 0;
iFilterMethod = NULL;
iSrcDir = pSrcDirName;
iDestDir = pDestDirName;
//mkdir(iDestDir);
init();
}
//=================================================================
TileAssembler::~TileAssembler()
{
delete iCoordModelMapping;
}
//=================================================================
void TileAssembler::init()
{
iCoordModelMapping = new CoordModelMapping();
addWorldAreaMapId(0); //Azeroth
addWorldAreaMapId(1); //Kalimdor
addWorldAreaMapId(530); //Expansion01
}
//=================================================================
std::string getModNameFromModPosName(const std::string& pModPosName)
{
size_t spos = pModPosName.find_first_of('#');
std::string modelFileName = pModPosName.substr(0,spos);
return(modelFileName);
}
//=================================================================
unsigned int TileAssembler::getUniqueNameId(const std::string pName)
{
unsigned int result;
if(!iUniqueNameIds.containsKey(pName))
{
iCurrentUniqueNameId++;
iUniqueNameIds.set(pName, iCurrentUniqueNameId);
}
result = iUniqueNameIds.get(pName);
return result;
}
//=================================================================
std::string TileAssembler::getDirEntryNameFromModName(unsigned int pMapId, const std::string& pModPosName)
{
size_t spos;
char buffer[20];
std::string modelFileName = getModNameFromModPosName(pModPosName);
//std::string fext = pModPosName.substr(modelFileName.length(),pModPosName.length());
unsigned int fextId = getUniqueNameId(pModPosName);
sprintf(buffer, "_%07d",fextId);
std::string fext(buffer);
spos = modelFileName.find_last_of('/');
std::string fname = modelFileName.substr(spos+1, modelFileName.length());
spos = fname.find_last_of('.');
fname = fname.substr(0,spos);
sprintf(buffer, "%03u", pMapId);
std::string dirEntry(buffer);
dirEntry.append("_");
dirEntry.append(fname);
dirEntry.append(fext);
dirEntry.append(".vmap");
return(dirEntry);
}
//=================================================================
void emptyArray(Array<ModelContainer*>& mc)
{
int no=mc.size();
while(no > 0)
{
--no;
delete mc[no];
mc.remove(no);
}
}
//=================================================================
bool TileAssembler::convertWorld()
{
#ifdef _ASSEMBLER_DEBUG
# ifdef _DEBUG
::g_df = fopen("../TileAssembler_debug.txt", "wb");
# else
::g_df = fopen("../TileAssembler_release.txt", "wb");
# endif
#endif
bool result = true;
std::string fname = iSrcDir;
fname.append("/");
fname.append("dir");
iCoordModelMapping->setModelNameFilterMethod(iFilterMethod);
iCoordModelMapping->readCoordinateMapping(fname);
Array<unsigned int> mapIds = iCoordModelMapping->getMaps();
if(mapIds.size() == 0)
{
result = false;
}
for(int i=0; i<mapIds.size() && result; ++i)
{
unsigned int mapId = mapIds[i];
#ifdef _ASSEMBLER_DEBUG
if(mapId == 0) // "Azeroth" just for debug
{
for(int x=28; x<29 && result; ++x) //debug
{
for(int y=28; y<29 && result; ++y)
{
#else
// ignore DeeprunTram (369) it is too large for short vector and not important
// ignore test (13), Test (29) , development (451)
if(mapId != 369 && mapId != 13 && mapId != 29 && mapId != 451)
{
for(int x=0; x<66 && result; ++x)
{
for(int y=0; y<66 && result; ++y)
{
#endif
Array<ModelContainer*> mc;
std::string dirname;
char buffer[100];
if(iCoordModelMapping->isWorldAreaMap(mapId) && x<65 && y<65)
{
sprintf(buffer, "%03u_%d_%d",mapId,x,y);
dirname = std::string(buffer);
}
else
{
sprintf(buffer, "%03u",mapId);
dirname = std::string(buffer);
}
result = fillModelContainerArray(dirname, mapId, x, y, mc);
emptyArray(mc);
}
}
}
}
#ifdef _ASSEMBLER_DEBUG
if(::g_df) fclose(::g_df);
#endif
return result;
}
//=================================================================
bool TileAssembler::fillModelContainerArray(const std::string& pDirFileName, unsigned int pMapId, int pXPos, int pYPos, Array<ModelContainer*>& pMC)
{
bool result = true;
ModelContainer* modelContainer;
NameCollection nameCollection = iCoordModelMapping->getFilenamesForCoordinate(pMapId, pXPos, pYPos);
if(nameCollection.size() > 0)
{
result = false;
char dirfilename[500];
sprintf(dirfilename,"%s/%s.vmdir",iDestDir.c_str(),pDirFileName.c_str());
FILE *dirfile = fopen(dirfilename, "ab");
if(dirfile)
{
result = true;
char destnamebuffer[500];
char fullnamedestnamebuffer[500];
if(nameCollection.iMainFiles.size() >0)
{
sprintf(destnamebuffer,"%03u_%i_%i.vmap",pMapId, pXPos, pYPos);
std::string checkDoubleStr = std::string(dirfilename);
checkDoubleStr.append("##");
checkDoubleStr.append(std::string(destnamebuffer));
// Check, if same file already is in the same dir file
if(!iCoordModelMapping->isAlreadyProcessedSingleFile(checkDoubleStr))
{
iCoordModelMapping->addAlreadyProcessedSingleFile(checkDoubleStr);
fprintf(dirfile, "%s\n",destnamebuffer);
sprintf(fullnamedestnamebuffer,"%s/%s",iDestDir.c_str(),destnamebuffer);
modelContainer = processNames(nameCollection.iMainFiles, fullnamedestnamebuffer);
if(modelContainer)
{
pMC.append(modelContainer);
}
else
{
result = false;
}
}
}
// process the large singe files
int pos = 0;
while(result && (pos < nameCollection.iSingeFiles.size()))
{
std::string destFileName = iDestDir;
destFileName.append("/");
std::string dirEntryName = getDirEntryNameFromModName(pMapId,nameCollection.iSingeFiles[pos]);
std::string checkDoubleStr = std::string(dirfilename);
checkDoubleStr.append("##");
checkDoubleStr.append(nameCollection.iSingeFiles[pos]);
// Check, if same file already is in the same dir file
if(!iCoordModelMapping->isAlreadyProcessedSingleFile(checkDoubleStr))
{
iCoordModelMapping->addAlreadyProcessedSingleFile(checkDoubleStr);
fprintf(dirfile, "%s\n",dirEntryName.c_str());
destFileName.append(dirEntryName);
Array<std::string> positionarray;
positionarray.append(nameCollection.iSingeFiles[pos]);
if(!iCoordModelMapping->isAlreadyProcessedSingleFile(nameCollection.iSingeFiles[pos]))
{
modelContainer = processNames(positionarray, destFileName.c_str());
iCoordModelMapping->addAlreadyProcessedSingleFile(nameCollection.iSingeFiles[pos]);
if(modelContainer)
{
pMC.append(modelContainer);
}
else
{
result = false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -