mirror of
https://github.com/mangosfour/server.git
synced 2025-12-27 10:37:02 +00:00
Merge commit 'origin/master' into 310
Conflicts: src/game/SpellAuras.cpp
This commit is contained in:
commit
cae3f0a532
53 changed files with 1074 additions and 954 deletions
|
|
@ -370,7 +370,7 @@ class ByteBuffer
|
|||
{
|
||||
if ((i == (j*8)) && ((i != (k*16))))
|
||||
{
|
||||
if (read<uint8>(i) < 0x0F)
|
||||
if (read<uint8>(i) < 0x10)
|
||||
{
|
||||
sLog.outDebugInLine("| 0%X ", read<uint8>(i) );
|
||||
}
|
||||
|
|
@ -382,7 +382,7 @@ class ByteBuffer
|
|||
}
|
||||
else if (i == (k*16))
|
||||
{
|
||||
if (read<uint8>(i) < 0x0F)
|
||||
if (read<uint8>(i) < 0x10)
|
||||
{
|
||||
sLog.outDebugInLine("\n");
|
||||
if(sLog.IsIncludeTime())
|
||||
|
|
@ -404,7 +404,7 @@ class ByteBuffer
|
|||
}
|
||||
else
|
||||
{
|
||||
if (read<uint8>(i) < 0x0F)
|
||||
if (read<uint8>(i) < 0x10)
|
||||
{
|
||||
sLog.outDebugInLine("0%X ", read<uint8>(i) );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,6 +98,7 @@
|
|||
#include "LockedQueue.h"
|
||||
#include "Threading.h"
|
||||
|
||||
#include <ace/Basic_Types.h>
|
||||
#include <ace/Guard_T.h>
|
||||
#include <ace/RW_Thread_Mutex.h>
|
||||
#include <ace/Thread_Mutex.h>
|
||||
|
|
@ -125,8 +126,6 @@
|
|||
#include <float.h>
|
||||
|
||||
#define I64FMT "%016I64X"
|
||||
#define I64FMTD "%I64u"
|
||||
#define SI64FMTD "%I64d"
|
||||
#define snprintf _snprintf
|
||||
#define atoll __atoi64
|
||||
#define vsnprintf _vsnprintf
|
||||
|
|
@ -138,10 +137,15 @@
|
|||
#define stricmp strcasecmp
|
||||
#define strnicmp strncasecmp
|
||||
#define I64FMT "%016llX"
|
||||
#define I64FMTD "%llu"
|
||||
#define SI64FMTD "%lld"
|
||||
|
||||
#endif
|
||||
|
||||
#define UI64FMTD ACE_UINT64_FORMAT_SPECIFIER
|
||||
#define UI64LIT(N) ACE_UINT64_LITERAL(N)
|
||||
|
||||
#define SI64FMTD ACE_INT64_FORMAT_SPECIFIER
|
||||
#define SI64LIT(N) ACE_INT64_LITERAL(N)
|
||||
|
||||
inline float finiteAlways(float f) { return finite(f) ? f : 0.0f; }
|
||||
|
||||
#define atol(a) strtoul( a, NULL, 10)
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class Field
|
|||
if(mValue)
|
||||
{
|
||||
uint64 value;
|
||||
sscanf(mValue,I64FMTD,&value);
|
||||
sscanf(mValue,UI64FMTD,&value);
|
||||
return value;
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef __REVISION_NR_H__
|
||||
#define __REVISION_NR_H__
|
||||
#define REVISION_NR "7911"
|
||||
#define REVISION_NR "7928"
|
||||
#endif // __REVISION_NR_H__
|
||||
|
|
|
|||
|
|
@ -85,63 +85,65 @@ namespace VMAP
|
|||
bool CoordModelMapping::readCoordinateMapping(const std::string& pDirectoryFileName)
|
||||
{
|
||||
FILE *f = fopen(pDirectoryFileName.c_str(), "rb");
|
||||
bool result = false;
|
||||
if(!f)
|
||||
{
|
||||
printf("ERROR: Can't open file: %s\n",pDirectoryFileName.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
char buffer[500+1];
|
||||
|
||||
if(f)
|
||||
CMappingEntry* cMappingEntry;
|
||||
while(fgets(buffer, 500, f))
|
||||
{
|
||||
result = true;
|
||||
CMappingEntry* cMappingEntry;
|
||||
while(fgets(buffer, 500, f))
|
||||
//char namebuffer[500];
|
||||
char positionbuffer[500];
|
||||
int xpos, ypos, noVec;
|
||||
float scale;
|
||||
xpos = ypos = noVec = 0;
|
||||
|
||||
//sscanf(buffer, "%d %d %s %s %f %d", &xpos, &ypos, namebuffer,positionbuffer, &scale, &noVec);
|
||||
|
||||
// this is ugly, but the format has no read delimiter and a space could be in the first part of the name
|
||||
int nameStart = findPosChar(buffer, ' ', 2);// find the 2. space
|
||||
if(nameStart > -1 && (iFilterMethod == NULL || (*iFilterMethod)(buffer)))
|
||||
{
|
||||
//char namebuffer[500];
|
||||
char positionbuffer[500];
|
||||
int xpos, ypos, noVec;
|
||||
float scale;
|
||||
xpos = ypos = noVec = 0;
|
||||
++nameStart;
|
||||
// find the 1. / (now a space only can be found at the end of the name)
|
||||
int nameEnd = nameStart + findPosChar(&buffer[nameStart], '/', 1);
|
||||
// find the 1. space (after the name)
|
||||
nameEnd += findPosChar(&buffer[nameEnd], ' ', 1);
|
||||
buffer[nameEnd] = 0; // terminate the name
|
||||
|
||||
//sscanf(buffer, "%d %d %s %s %f %d", &xpos, &ypos, namebuffer,positionbuffer, &scale, &noVec);
|
||||
|
||||
// this is ugly, but the format has no read delimiter and a space could be in the first part of the name
|
||||
int nameStart = findPosChar(buffer, ' ', 2);// find the 2. space
|
||||
if(nameStart > -1 && (iFilterMethod == NULL || (*iFilterMethod)(buffer)))
|
||||
sscanf(buffer, "%d %d", &xpos, &ypos);
|
||||
sscanf(&buffer[nameEnd+1], "%s %f %d", positionbuffer, &scale, &noVec);
|
||||
unsigned int mapId = getMapIdFromFilename(std::string(&buffer[nameStart]));
|
||||
if(!iMapIds.contains(mapId))
|
||||
{
|
||||
++nameStart;
|
||||
// find the 1. / (now a space only can be found at the end of the name)
|
||||
int nameEnd = nameStart + findPosChar(&buffer[nameStart], '/', 1);
|
||||
// find the 1. space (after the name)
|
||||
nameEnd += findPosChar(&buffer[nameEnd], ' ', 1);
|
||||
buffer[nameEnd] = 0; // terminate the name
|
||||
|
||||
sscanf(buffer, "%d %d", &xpos, &ypos);
|
||||
sscanf(&buffer[nameEnd+1], "%s %f %d", positionbuffer, &scale, &noVec);
|
||||
unsigned int mapId = getMapIdFromFilename(std::string(&buffer[nameStart]));
|
||||
if(!iMapIds.contains(mapId))
|
||||
{
|
||||
iMapIds.append(mapId);
|
||||
}
|
||||
if(!isWorldAreaMap(mapId))
|
||||
{
|
||||
xpos = 0; // store all files under the groupKey
|
||||
ypos = 0;
|
||||
}
|
||||
|
||||
std::string key = CMappingEntry::getKeyString(mapId, xpos, ypos);
|
||||
cMappingEntry = getCMappingEntry(key);
|
||||
if(cMappingEntry == 0)
|
||||
{
|
||||
cMappingEntry = new CMappingEntry(mapId, xpos, ypos);
|
||||
addCMappingEntry(cMappingEntry);
|
||||
}
|
||||
char namebuffer2[500];
|
||||
sprintf(namebuffer2, "%d %s#%s_%f", noVec, &buffer[nameStart], positionbuffer, scale);
|
||||
cMappingEntry->addFilename(namebuffer2);
|
||||
//break;
|
||||
iMapIds.append(mapId);
|
||||
printf("Coords for map %u...\n",mapId);
|
||||
}
|
||||
if(!isWorldAreaMap(mapId))
|
||||
{
|
||||
xpos = 0; // store all files under the groupKey
|
||||
ypos = 0;
|
||||
}
|
||||
|
||||
std::string key = CMappingEntry::getKeyString(mapId, xpos, ypos);
|
||||
cMappingEntry = getCMappingEntry(key);
|
||||
if(cMappingEntry == 0)
|
||||
{
|
||||
cMappingEntry = new CMappingEntry(mapId, xpos, ypos);
|
||||
addCMappingEntry(cMappingEntry);
|
||||
}
|
||||
char namebuffer2[500];
|
||||
sprintf(namebuffer2, "%d %s#%s_%f", noVec, &buffer[nameStart], positionbuffer, scale);
|
||||
cMappingEntry->addFilename(namebuffer2);
|
||||
//break;
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
return result;
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
//============================================================
|
||||
|
|
|
|||
|
|
@ -148,446 +148,454 @@ namespace VMAP
|
|||
# endif
|
||||
#endif
|
||||
|
||||
bool result = true;
|
||||
std::string fname = iSrcDir;
|
||||
fname.append("/");
|
||||
fname.append("dir");
|
||||
iCoordModelMapping->setModelNameFilterMethod(iFilterMethod);
|
||||
iCoordModelMapping->readCoordinateMapping(fname);
|
||||
|
||||
printf("Read coordinate mapping...\n");
|
||||
if(!iCoordModelMapping->readCoordinateMapping(fname))
|
||||
return false;
|
||||
|
||||
Array<unsigned int> mapIds = iCoordModelMapping->getMaps();
|
||||
if(mapIds.size() == 0)
|
||||
{
|
||||
result = false;
|
||||
printf("Fatal error: empty map list!\n");
|
||||
return false;
|
||||
}
|
||||
for(int i=0; i<mapIds.size() && result; ++i)
|
||||
|
||||
for(int i=0; i<mapIds.size(); ++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 x=28; x<29; ++x) //debug
|
||||
{
|
||||
for(int y=28; y<29 && result; ++y)
|
||||
for(int y=28; y<29; ++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,y,x); // Let's flip x and y here
|
||||
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)
|
||||
#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; ++x)
|
||||
{
|
||||
bool result = true;
|
||||
ModelContainer* modelContainer;
|
||||
|
||||
NameCollection nameCollection = iCoordModelMapping->getFilenamesForCoordinate(pMapId, pXPos, pYPos);
|
||||
if(nameCollection.size() > 0)
|
||||
for(int y=0; y<66; ++y)
|
||||
{
|
||||
result = false;
|
||||
char dirfilename[500];
|
||||
sprintf(dirfilename,"%s/%s.vmdir",iDestDir.c_str(),pDirFileName.c_str());
|
||||
FILE *dirfile = fopen(dirfilename, "ab");
|
||||
if(dirfile)
|
||||
#endif
|
||||
Array<ModelContainer*> mc;
|
||||
std::string dirname;
|
||||
char buffer[100];
|
||||
if(iCoordModelMapping->isWorldAreaMap(mapId) && x<65 && y<65)
|
||||
{
|
||||
result = true;
|
||||
char destnamebuffer[500];
|
||||
char fullnamedestnamebuffer[500];
|
||||
if(nameCollection.iMainFiles.size() >0)
|
||||
{
|
||||
sprintf(destnamebuffer,"%03u_%i_%i.vmap",pMapId, pYPos, pXPos); // flip it here too
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
++pos;
|
||||
}
|
||||
fclose(dirfile);
|
||||
}
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
//=================================================================
|
||||
|
||||
void removeEntriesFromTree(AABSPTree<SubModel *>* pTree)
|
||||
{
|
||||
Array<SubModel *> submodelArray;
|
||||
pTree->getMembers(submodelArray);
|
||||
int no = submodelArray.size();
|
||||
while(no > 0)
|
||||
{
|
||||
--no;
|
||||
delete submodelArray[no];
|
||||
}
|
||||
}
|
||||
|
||||
//=================================================================
|
||||
|
||||
ModelContainer* TileAssembler::processNames(const Array<std::string>& pPositions, const char* pDestFileName)
|
||||
{
|
||||
ModelContainer *modelContainer = 0;
|
||||
|
||||
Vector3 basepos = Vector3(0,0,0);
|
||||
AABSPTree<SubModel *>* mainTree = new AABSPTree<SubModel *>();
|
||||
|
||||
int pos = 0;
|
||||
|
||||
bool result = true;
|
||||
while(result && (pos < pPositions.size()))
|
||||
{
|
||||
std::string modelPosString = pPositions[pos];
|
||||
std::string modelFileName = getModNameFromModPosName(modelPosString);
|
||||
|
||||
if(!fillModelIntoTree(mainTree, basepos, modelPosString, modelFileName))
|
||||
{
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
++pos;
|
||||
}
|
||||
if(result && mainTree->size() > 0)
|
||||
{
|
||||
mainTree->balance();
|
||||
modelContainer = new ModelContainer(mainTree);
|
||||
modelContainer->writeFile(pDestFileName);
|
||||
}
|
||||
removeEntriesFromTree(mainTree);
|
||||
|
||||
delete mainTree;
|
||||
|
||||
return(modelContainer);
|
||||
}
|
||||
|
||||
//=================================================================
|
||||
bool TileAssembler::readRawFile(std::string& pModelFilename, ModelPosition& pModelPosition, AABSPTree<SubModel *> *pMainTree)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
std::string filename = iSrcDir;
|
||||
if(filename.length() >0)
|
||||
filename.append("/");
|
||||
filename.append(pModelFilename);
|
||||
FILE *rf = fopen(filename.c_str(), "rb");
|
||||
if(!rf)
|
||||
{
|
||||
// depending on the extractor version, the data could be located in the root dir
|
||||
std::string baseModelFilename = pModelFilename.substr((pModelFilename.find_first_of("/")+1),pModelFilename.length());
|
||||
filename = iSrcDir;
|
||||
if(filename.length() >0)
|
||||
filename.append("/");
|
||||
filename.append(baseModelFilename);
|
||||
rf = fopen(filename.c_str(), "rb");
|
||||
}
|
||||
char ident[8];
|
||||
|
||||
int trianglecount =0;
|
||||
|
||||
#ifdef _ASSEMBLER_DEBUG
|
||||
int startgroup = 0; //2;
|
||||
int endgroup = INT_MAX; //2;
|
||||
fprintf(::g_df,"-------------------------------------------------\n");
|
||||
fprintf(::g_df,"%s\n", pModelFilename.c_str());
|
||||
fprintf(::g_df,"-------------------------------------------------\n");
|
||||
#else
|
||||
int startgroup = 0;
|
||||
int endgroup = INT_MAX;
|
||||
#endif
|
||||
|
||||
// temporary use defines to simplify read/check code (close file and return at fail)
|
||||
#define READ_OR_RETURN(V,S) if(fread((V), (S), 1, rf) != 1) { fclose(rf); return(false); }
|
||||
#define CMP_OR_RETURN(V,S) if(strcmp((V),(S)) != 0) { fclose(rf); return(false); }
|
||||
|
||||
if(rf)
|
||||
{
|
||||
READ_OR_RETURN(&ident, 8);
|
||||
if(strcmp(ident, "VMAP001") == 0)
|
||||
{
|
||||
// OK, do nothing
|
||||
}
|
||||
else if(strcmp(ident, "VMAP002") == 0)
|
||||
{
|
||||
// we have to read one int. This is needed during the export and we have to skip it here
|
||||
int tempNVectors;
|
||||
READ_OR_RETURN(&tempNVectors, sizeof(int));
|
||||
|
||||
sprintf(buffer, "%03u_%d_%d",mapId,y,x); // Let's flip x and y here
|
||||
dirname = std::string(buffer);
|
||||
printf("%s...\n",dirname.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
// wrong version
|
||||
fclose(rf);
|
||||
return(false);
|
||||
sprintf(buffer, "%03u",mapId);
|
||||
dirname = std::string(buffer);
|
||||
|
||||
// prevent spam for small maps
|
||||
if(x==0 && y==0)
|
||||
printf("%s...\n",dirname.c_str());
|
||||
}
|
||||
G3D::uint32 groups;
|
||||
char blockId[5];
|
||||
blockId[4] = 0;
|
||||
int blocksize;
|
||||
|
||||
READ_OR_RETURN(&groups, sizeof(G3D::uint32));
|
||||
bool result = fillModelContainerArray(dirname, mapId, x, y, mc);
|
||||
emptyArray(mc);
|
||||
|
||||
for(int g=0;g<(int)groups;g++)
|
||||
{
|
||||
// group MUST NOT have more then 65536 indexes !! Array will have a problem with that !! (strange ...)
|
||||
Array<int> tempIndexArray;
|
||||
Array<Vector3> tempVertexArray;
|
||||
|
||||
AABSPTree<Triangle> *gtree = new AABSPTree<Triangle>();
|
||||
|
||||
// add free gtree at fail
|
||||
#undef READ_OR_RETURN
|
||||
#undef CMP_OR_RETURN
|
||||
#define READ_OR_RETURN(V,S) if(fread((V), (S), 1, rf) != 1) { fclose(rf); delete gtree; return(false); }
|
||||
#define CMP_OR_RETURN(V,S) if(strcmp((V),(S)) != 0) { fclose(rf); delete gtree; return(false); }
|
||||
|
||||
G3D::uint32 flags;
|
||||
READ_OR_RETURN(&flags, sizeof(G3D::uint32));
|
||||
|
||||
G3D::uint32 branches;
|
||||
READ_OR_RETURN(&blockId, 4);
|
||||
CMP_OR_RETURN(blockId, "GRP ");
|
||||
READ_OR_RETURN(&blocksize, sizeof(int));
|
||||
READ_OR_RETURN(&branches, sizeof(G3D::uint32));
|
||||
for(int b=0;b<(int)branches; b++)
|
||||
{
|
||||
G3D::uint32 indexes;
|
||||
// indexes for each branch (not used jet)
|
||||
READ_OR_RETURN(&indexes, sizeof(G3D::uint32));
|
||||
}
|
||||
|
||||
// ---- indexes
|
||||
READ_OR_RETURN(&blockId, 4);
|
||||
CMP_OR_RETURN(blockId, "INDX");
|
||||
READ_OR_RETURN(&blocksize, sizeof(int));
|
||||
unsigned int nindexes;
|
||||
READ_OR_RETURN(&nindexes, sizeof(G3D::uint32));
|
||||
if(nindexes >0)
|
||||
{
|
||||
unsigned short *indexarray = new unsigned short[nindexes*sizeof(unsigned short)];
|
||||
READ_OR_RETURN(indexarray, sizeof(unsigned short));
|
||||
for(int i=0;i<(int)nindexes; i++)
|
||||
{
|
||||
unsigned short val = indexarray[i];
|
||||
tempIndexArray.append(val);
|
||||
}
|
||||
delete[] indexarray;
|
||||
}
|
||||
|
||||
// ---- vectors
|
||||
READ_OR_RETURN(&blockId, 4);
|
||||
CMP_OR_RETURN(blockId, "VERT");
|
||||
READ_OR_RETURN(&blocksize, sizeof(int));
|
||||
unsigned int nvectors;
|
||||
READ_OR_RETURN(&nvectors, sizeof(int));
|
||||
|
||||
float *vectorarray = 0;
|
||||
|
||||
// add vectorarray free
|
||||
#undef READ_OR_RETURN
|
||||
#undef CMP_OR_RETURN
|
||||
#define READ_OR_RETURN(V,S) if(fread((V), (S), 1, rf) != 1) { fclose(rf); delete gtree; delete[] vectorarray; return(false); }
|
||||
#define CMP_OR_RETURN(V,S) if(strcmp((V),(S)) != 0) { fclose(rf); delete gtree; delete[] vectorarray; return(false); }
|
||||
|
||||
if(nvectors >0)
|
||||
{
|
||||
vectorarray = new float[nvectors*sizeof(float)*3];
|
||||
READ_OR_RETURN(vectorarray, sizeof(float)*3);
|
||||
}
|
||||
// ----- liquit
|
||||
if(flags & 1)
|
||||
{
|
||||
// we have liquit -> not handled yet ... skip
|
||||
READ_OR_RETURN(&blockId, 4);
|
||||
CMP_OR_RETURN(blockId, "LIQU");
|
||||
READ_OR_RETURN(&blocksize, sizeof(int));
|
||||
fseek(rf, blocksize, SEEK_CUR);
|
||||
}
|
||||
|
||||
|
||||
for(unsigned int i=0, indexNo=0; indexNo<nvectors; indexNo++)
|
||||
{
|
||||
Vector3 v = Vector3(vectorarray[i+2], vectorarray[i+1], vectorarray[i+0]);
|
||||
i+=3;
|
||||
v = pModelPosition.transform(v);
|
||||
|
||||
float swapy = v.y;
|
||||
v.y = v.x;
|
||||
v.x = swapy;
|
||||
|
||||
tempVertexArray.append(v);
|
||||
}
|
||||
|
||||
// ---- calculate triangles
|
||||
int rest = nindexes%3;
|
||||
if(rest != 0)
|
||||
{
|
||||
nindexes -= rest;
|
||||
}
|
||||
|
||||
for(unsigned int i=0;i<(nindexes);)
|
||||
{
|
||||
Triangle t = Triangle(tempVertexArray[tempIndexArray[i+2]], tempVertexArray[tempIndexArray[i+1]], tempVertexArray[tempIndexArray[i+0]] );
|
||||
i+=3;
|
||||
++trianglecount;
|
||||
if(g>= startgroup && g <= endgroup)
|
||||
{
|
||||
gtree->insert(t);
|
||||
}
|
||||
}
|
||||
|
||||
// drop of temporary use defines
|
||||
#undef READ_OR_RETURN
|
||||
#undef CMP_OR_RETURN
|
||||
|
||||
if(vectorarray != 0)
|
||||
{
|
||||
delete vectorarray;
|
||||
}
|
||||
|
||||
if(gtree->size() >0)
|
||||
{
|
||||
gtree->balance();
|
||||
SubModel *sm = new SubModel(gtree);
|
||||
#ifdef _ASSEMBLER_DEBUG
|
||||
if(::g_df) fprintf(::g_df,"group trianglies: %d, Tris: %d, Nodes: %d, gtree.triangles: %d\n", g, sm->getNTriangles(), sm->getNNodes(), gtree->memberTable.size());
|
||||
if(sm->getNTriangles() != gtree->memberTable.size())
|
||||
{
|
||||
if(::g_df) fprintf(::g_df,"ERROR !!!! group trianglies: %d, Tris: %d, Nodes: %d, gtree.triangles: %d\n", g, sm->getNTriangles(), sm->getNNodes(), gtree->memberTable.size());
|
||||
}
|
||||
#endif
|
||||
sm->setBasePosition(pModelPosition.iPos);
|
||||
pMainTree->insert(sm);
|
||||
}
|
||||
delete gtree;
|
||||
}
|
||||
fclose(rf);
|
||||
result = true;
|
||||
if(!result)
|
||||
return false;
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef _ASSEMBLER_DEBUG
|
||||
if(::g_df) fclose(::g_df);
|
||||
#endif
|
||||
|
||||
//=================================================================
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TileAssembler::fillModelIntoTree(AABSPTree<SubModel *> *pMainTree, const Vector3& pBasePos, std::string& pPos, std::string& pModelFilename)
|
||||
//=================================================================
|
||||
|
||||
bool TileAssembler::fillModelContainerArray(const std::string& pDirFileName, unsigned int pMapId, int pXPos, int pYPos, Array<ModelContainer*>& pMC)
|
||||
{
|
||||
ModelContainer* modelContainer;
|
||||
|
||||
NameCollection nameCollection = iCoordModelMapping->getFilenamesForCoordinate(pMapId, pXPos, pYPos);
|
||||
if(nameCollection.size() == 0)
|
||||
return true; // no data...
|
||||
|
||||
char dirfilename[500];
|
||||
sprintf(dirfilename,"%s/%s.vmdir",iDestDir.c_str(),pDirFileName.c_str());
|
||||
FILE *dirfile = fopen(dirfilename, "ab");
|
||||
if(!dirfile)
|
||||
{
|
||||
printf("ERROR: Can't create file %s",dirfilename);
|
||||
return false;
|
||||
}
|
||||
|
||||
char destnamebuffer[500];
|
||||
char fullnamedestnamebuffer[500];
|
||||
|
||||
if(nameCollection.iMainFiles.size() >0)
|
||||
{
|
||||
sprintf(destnamebuffer,"%03u_%i_%i.vmap",pMapId, pYPos, pXPos); // flip it here too
|
||||
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
|
||||
printf("warning: (if) problems in processing data for %s\n",destnamebuffer);
|
||||
}
|
||||
}
|
||||
// process the large singe files
|
||||
int pos = 0;
|
||||
while(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]))
|
||||
{
|
||||
bool result = false;
|
||||
ModelPosition modelPosition;
|
||||
getModelPosition(pPos, modelPosition);
|
||||
// all should be relative to object base position
|
||||
modelPosition.moveToBasePos(pBasePos);
|
||||
|
||||
modelPosition.init();
|
||||
|
||||
if(readRawFile(pModelFilename, modelPosition, pMainTree))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
modelContainer = processNames(positionarray, destFileName.c_str());
|
||||
iCoordModelMapping->addAlreadyProcessedSingleFile(nameCollection.iSingeFiles[pos]);
|
||||
if(modelContainer)
|
||||
pMC.append(modelContainer);
|
||||
else
|
||||
printf("warning: (while) problems in processing data for %s\n",destFileName.c_str());
|
||||
}
|
||||
}
|
||||
++pos;
|
||||
}
|
||||
|
||||
//=================================================================
|
||||
void TileAssembler::getModelPosition(std::string& pPosString, ModelPosition& pModelPosition)
|
||||
fclose(dirfile);
|
||||
return true;
|
||||
}
|
||||
|
||||
//=================================================================
|
||||
|
||||
void removeEntriesFromTree(AABSPTree<SubModel *>* pTree)
|
||||
{
|
||||
Array<SubModel *> submodelArray;
|
||||
pTree->getMembers(submodelArray);
|
||||
int no = submodelArray.size();
|
||||
while(no > 0)
|
||||
{
|
||||
--no;
|
||||
delete submodelArray[no];
|
||||
}
|
||||
}
|
||||
|
||||
//=================================================================
|
||||
|
||||
ModelContainer* TileAssembler::processNames(const Array<std::string>& pPositions, const char* pDestFileName)
|
||||
{
|
||||
ModelContainer *modelContainer = 0;
|
||||
|
||||
Vector3 basepos = Vector3(0,0,0);
|
||||
AABSPTree<SubModel *>* mainTree = new AABSPTree<SubModel *>();
|
||||
|
||||
int pos = 0;
|
||||
|
||||
bool result = true;
|
||||
while(result && (pos < pPositions.size()))
|
||||
{
|
||||
std::string modelPosString = pPositions[pos];
|
||||
std::string modelFileName = getModNameFromModPosName(modelPosString);
|
||||
|
||||
if(!fillModelIntoTree(mainTree, basepos, modelPosString, modelFileName))
|
||||
{
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
++pos;
|
||||
}
|
||||
if(result && mainTree->size() > 0)
|
||||
{
|
||||
mainTree->balance();
|
||||
modelContainer = new ModelContainer(mainTree);
|
||||
modelContainer->writeFile(pDestFileName);
|
||||
}
|
||||
removeEntriesFromTree(mainTree);
|
||||
|
||||
delete mainTree;
|
||||
|
||||
return(modelContainer);
|
||||
}
|
||||
|
||||
//=================================================================
|
||||
bool TileAssembler::readRawFile(std::string& pModelFilename, ModelPosition& pModelPosition, AABSPTree<SubModel *> *pMainTree)
|
||||
{
|
||||
std::string filename = iSrcDir;
|
||||
if(filename.length() >0)
|
||||
filename.append("/");
|
||||
filename.append(pModelFilename);
|
||||
FILE *rf = fopen(filename.c_str(), "rb");
|
||||
if(!rf)
|
||||
{
|
||||
// depending on the extractor version, the data could be located in the root dir
|
||||
std::string baseModelFilename = pModelFilename.substr((pModelFilename.find_first_of("/")+1),pModelFilename.length());
|
||||
filename = iSrcDir;
|
||||
if(filename.length() >0)
|
||||
filename.append("/");
|
||||
filename.append(baseModelFilename);
|
||||
rf = fopen(filename.c_str(), "rb");
|
||||
}
|
||||
|
||||
if(!rf)
|
||||
{
|
||||
printf("ERROR: Can't open model file in form: %s",pModelFilename.c_str());
|
||||
printf("... or form: %s",filename );
|
||||
return false;
|
||||
}
|
||||
|
||||
char ident[8];
|
||||
|
||||
int trianglecount =0;
|
||||
|
||||
#ifdef _ASSEMBLER_DEBUG
|
||||
int startgroup = 0; //2;
|
||||
int endgroup = INT_MAX; //2;
|
||||
fprintf(::g_df,"-------------------------------------------------\n");
|
||||
fprintf(::g_df,"%s\n", pModelFilename.c_str());
|
||||
fprintf(::g_df,"-------------------------------------------------\n");
|
||||
#else
|
||||
int startgroup = 0;
|
||||
int endgroup = INT_MAX;
|
||||
#endif
|
||||
|
||||
// temporary use defines to simplify read/check code (close file and return at fail)
|
||||
#define READ_OR_RETURN(V,S) if(fread((V), (S), 1, rf) != 1) { \
|
||||
fclose(rf); return(false); }
|
||||
#define CMP_OR_RETURN(V,S) if(strcmp((V),(S)) != 0) { \
|
||||
fclose(rf); return(false); }
|
||||
|
||||
READ_OR_RETURN(&ident, 8);
|
||||
if(strcmp(ident, "VMAP001") == 0)
|
||||
{
|
||||
// OK, do nothing
|
||||
}
|
||||
else if(strcmp(ident, "VMAP002") == 0)
|
||||
{
|
||||
// we have to read one int. This is needed during the export and we have to skip it here
|
||||
int tempNVectors;
|
||||
READ_OR_RETURN(&tempNVectors, sizeof(int));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// wrong version
|
||||
fclose(rf);
|
||||
return(false);
|
||||
}
|
||||
G3D::uint32 groups;
|
||||
char blockId[5];
|
||||
blockId[4] = 0;
|
||||
int blocksize;
|
||||
|
||||
READ_OR_RETURN(&groups, sizeof(G3D::uint32));
|
||||
|
||||
for(int g=0;g<(int)groups;g++)
|
||||
{
|
||||
// group MUST NOT have more then 65536 indexes !! Array will have a problem with that !! (strange ...)
|
||||
Array<int> tempIndexArray;
|
||||
Array<Vector3> tempVertexArray;
|
||||
|
||||
AABSPTree<Triangle> *gtree = new AABSPTree<Triangle>();
|
||||
|
||||
// add free gtree at fail
|
||||
#undef READ_OR_RETURN
|
||||
#undef CMP_OR_RETURN
|
||||
#define READ_OR_RETURN(V,S) if(fread((V), (S), 1, rf) != 1) { \
|
||||
fclose(rf); delete gtree; return(false); }
|
||||
#define CMP_OR_RETURN(V,S) if(strcmp((V),(S)) != 0) { \
|
||||
fclose(rf); delete gtree; return(false); }
|
||||
|
||||
G3D::uint32 flags;
|
||||
READ_OR_RETURN(&flags, sizeof(G3D::uint32));
|
||||
|
||||
G3D::uint32 branches;
|
||||
READ_OR_RETURN(&blockId, 4);
|
||||
CMP_OR_RETURN(blockId, "GRP ");
|
||||
READ_OR_RETURN(&blocksize, sizeof(int));
|
||||
READ_OR_RETURN(&branches, sizeof(G3D::uint32));
|
||||
for(int b=0;b<(int)branches; b++)
|
||||
{
|
||||
G3D::uint32 indexes;
|
||||
// indexes for each branch (not used jet)
|
||||
READ_OR_RETURN(&indexes, sizeof(G3D::uint32));
|
||||
}
|
||||
|
||||
// ---- indexes
|
||||
READ_OR_RETURN(&blockId, 4);
|
||||
CMP_OR_RETURN(blockId, "INDX");
|
||||
READ_OR_RETURN(&blocksize, sizeof(int));
|
||||
unsigned int nindexes;
|
||||
READ_OR_RETURN(&nindexes, sizeof(G3D::uint32));
|
||||
if(nindexes >0)
|
||||
{
|
||||
unsigned short *indexarray = new unsigned short[nindexes*sizeof(unsigned short)];
|
||||
READ_OR_RETURN(indexarray, nindexes*sizeof(unsigned short));
|
||||
for(int i=0;i<(int)nindexes; i++)
|
||||
{
|
||||
float vposarray[3];
|
||||
float vdirarray[3];
|
||||
float scale;
|
||||
|
||||
size_t spos = pPosString.find_first_of('#');
|
||||
std::string stripedPosString = pPosString.substr(spos+1,pPosString.length());
|
||||
|
||||
sscanf(stripedPosString.c_str(), "%f,%f,%f_%f,%f,%f_%f",
|
||||
&vposarray[0],&vposarray[1],&vposarray[2],
|
||||
&vdirarray[0],&vdirarray[1],&vdirarray[2],
|
||||
&scale);
|
||||
|
||||
pModelPosition.iPos = Vector3(vposarray[0], vposarray[1], vposarray[2]);
|
||||
pModelPosition.iDir = Vector3(vdirarray[0], vdirarray[1], vdirarray[2]);
|
||||
pModelPosition.iScale = scale;
|
||||
|
||||
unsigned short val = indexarray[i];
|
||||
tempIndexArray.append(val);
|
||||
}
|
||||
//==========================================
|
||||
delete[] indexarray;
|
||||
}
|
||||
|
||||
} // VMAP
|
||||
// ---- vectors
|
||||
READ_OR_RETURN(&blockId, 4);
|
||||
CMP_OR_RETURN(blockId, "VERT");
|
||||
READ_OR_RETURN(&blocksize, sizeof(int));
|
||||
unsigned int nvectors;
|
||||
READ_OR_RETURN(&nvectors, sizeof(int));
|
||||
|
||||
float *vectorarray = 0;
|
||||
|
||||
// add vectorarray free
|
||||
#undef READ_OR_RETURN
|
||||
#undef CMP_OR_RETURN
|
||||
#define READ_OR_RETURN(V,S) if(fread((V), (S), 1, rf) != 1) { \
|
||||
fclose(rf); delete gtree; delete[] vectorarray; return(false); }
|
||||
#define CMP_OR_RETURN(V,S) if(strcmp((V),(S)) != 0) { \
|
||||
fclose(rf); delete gtree; delete[] vectorarray; return(false); }
|
||||
|
||||
if(nvectors >0)
|
||||
{
|
||||
vectorarray = new float[nvectors*sizeof(float)*3];
|
||||
READ_OR_RETURN(vectorarray, nvectors*sizeof(float)*3);
|
||||
}
|
||||
// ----- liquit
|
||||
if(flags & 1)
|
||||
{
|
||||
// we have liquit -> not handled yet ... skip
|
||||
READ_OR_RETURN(&blockId, 4);
|
||||
CMP_OR_RETURN(blockId, "LIQU");
|
||||
READ_OR_RETURN(&blocksize, sizeof(int));
|
||||
fseek(rf, blocksize, SEEK_CUR);
|
||||
}
|
||||
|
||||
|
||||
for(unsigned int i=0, indexNo=0; indexNo<nvectors; indexNo++)
|
||||
{
|
||||
Vector3 v = Vector3(vectorarray[i+2], vectorarray[i+1], vectorarray[i+0]);
|
||||
i+=3;
|
||||
v = pModelPosition.transform(v);
|
||||
|
||||
float swapy = v.y;
|
||||
v.y = v.x;
|
||||
v.x = swapy;
|
||||
|
||||
tempVertexArray.append(v);
|
||||
}
|
||||
|
||||
// ---- calculate triangles
|
||||
int rest = nindexes%3;
|
||||
if(rest != 0)
|
||||
{
|
||||
nindexes -= rest;
|
||||
}
|
||||
|
||||
for(unsigned int i=0;i<(nindexes);)
|
||||
{
|
||||
Triangle t = Triangle(tempVertexArray[tempIndexArray[i+2]], tempVertexArray[tempIndexArray[i+1]], tempVertexArray[tempIndexArray[i+0]] );
|
||||
i+=3;
|
||||
++trianglecount;
|
||||
if(g>= startgroup && g <= endgroup)
|
||||
{
|
||||
gtree->insert(t);
|
||||
}
|
||||
}
|
||||
|
||||
// drop of temporary use defines
|
||||
#undef READ_OR_RETURN
|
||||
#undef CMP_OR_RETURN
|
||||
|
||||
if(vectorarray != 0)
|
||||
{
|
||||
delete vectorarray;
|
||||
}
|
||||
|
||||
if(gtree->size() >0)
|
||||
{
|
||||
gtree->balance();
|
||||
SubModel *sm = new SubModel(gtree);
|
||||
#ifdef _ASSEMBLER_DEBUG
|
||||
if(::g_df) fprintf(::g_df,"group trianglies: %d, Tris: %d, Nodes: %d, gtree.triangles: %d\n", g, sm->getNTriangles(), sm->getNNodes(), gtree->memberTable.size());
|
||||
if(sm->getNTriangles() != gtree->memberTable.size())
|
||||
{
|
||||
if(::g_df) fprintf(::g_df,"ERROR !!!! group trianglies: %d, Tris: %d, Nodes: %d, gtree.triangles: %d\n", g, sm->getNTriangles(), sm->getNNodes(), gtree->memberTable.size());
|
||||
}
|
||||
#endif
|
||||
sm->setBasePosition(pModelPosition.iPos);
|
||||
pMainTree->insert(sm);
|
||||
}
|
||||
delete gtree;
|
||||
}
|
||||
fclose(rf);
|
||||
return true;
|
||||
}
|
||||
|
||||
//=================================================================
|
||||
|
||||
bool TileAssembler::fillModelIntoTree(AABSPTree<SubModel *> *pMainTree, const Vector3& pBasePos, std::string& pPos, std::string& pModelFilename)
|
||||
{
|
||||
ModelPosition modelPosition;
|
||||
getModelPosition(pPos, modelPosition);
|
||||
// all should be relative to object base position
|
||||
modelPosition.moveToBasePos(pBasePos);
|
||||
|
||||
modelPosition.init();
|
||||
|
||||
return readRawFile(pModelFilename, modelPosition, pMainTree);
|
||||
}
|
||||
|
||||
//=================================================================
|
||||
void TileAssembler::getModelPosition(std::string& pPosString, ModelPosition& pModelPosition)
|
||||
{
|
||||
float vposarray[3];
|
||||
float vdirarray[3];
|
||||
float scale;
|
||||
|
||||
size_t spos = pPosString.find_first_of('#');
|
||||
std::string stripedPosString = pPosString.substr(spos+1,pPosString.length());
|
||||
|
||||
sscanf(stripedPosString.c_str(), "%f,%f,%f_%f,%f,%f_%f",
|
||||
&vposarray[0],&vposarray[1],&vposarray[2],
|
||||
&vdirarray[0],&vdirarray[1],&vdirarray[2],
|
||||
&scale);
|
||||
|
||||
pModelPosition.iPos = Vector3(vposarray[0], vposarray[1], vposarray[2]);
|
||||
pModelPosition.iDir = Vector3(vdirarray[0], vdirarray[1], vdirarray[2]);
|
||||
pModelPosition.iScale = scale;
|
||||
|
||||
}
|
||||
//==========================================
|
||||
} // VMAP
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue