//----------------------------------------------------------------------------- // Torque Game Engine // Copyright (C) GarageGames.com, Inc. //----------------------------------------------------------------------------- #include "ts/tsShapeConstruct.h" #include "console/consoleTypes.h" #include "core/fileStream.h" #include "core/bitStream.h" #define TS_IS_RELATIVE_SEQUENCES 0 IMPLEMENT_CO_DATABLOCK_V1(TSShapeConstructor); S32 gNumTransforms = 0; S32 gRotTransforms = 0; S32 gTransTransforms = 0; TSShapeConstructor::TSShapeConstructor() { mShape = NULL; for (S32 i = 0; iload(mShape); if(!bool(hShape)) return false; if (hShape->getSequencesConstructed()) return true; // We want to write into the resource: TSShape * shape = const_cast((const TSShape*)hShape); Stream * f; for (S32 i=0; iopenStream(fileBuf); if (!f || f->getStatus() != Stream::Ok) { dSprintf(errorBuffer, 256, "Missing sequence %s for %s",mSequence[i],mShape); error = true; continue; } if (!shape->importSequences(f) || f->getStatus()!=Stream::Ok) { ResourceManager->closeStream(f); dSprintf(errorBuffer, 256, "Load sequence %s failed for %s",mSequence[i],mShape); return false; } ResourceManager->closeStream(f); // if there was a space or tab in mSequence[i], then a new name was supplied for it // change it here...will still be in fileBuf if (terminate1 || terminate2) { // select the latter one: char * nameStart = terminate1sequences.last().nameIndex = shape->findName(nameStart); if (shape->sequences.last().nameIndex == -1) { shape->sequences.last().nameIndex = shape->names.size(); shape->names.increment(); shape->names.last() = StringTable->insert(nameStart,false); } } } else break; } if(!error) hShape->setSequencesConstructed(true); return !error; } void TSShapeConstructor::packData(BitStream* stream) { char *subtext; Parent::packData(stream); stream->writeString(mShape); S32 count = 0; for (S32 b=0; bwriteInt(count,NumSequenceBits); for (S32 i=0; iwriteString(subtext); } else { stream->writeString(mSequence[i]); } } } void TSShapeConstructor::unpackData(BitStream* stream) { S32 strLen,endLen,pathLen; char shapePath[90],pathedSeq[90]; char *subtext; Parent::unpackData(stream); mShape = stream->readSTString(); if (TS_IS_RELATIVE_SEQUENCES) { strLen = (int)dStrlen(mShape); subtext = (char*)dStrrchr(mShape,'/'); endLen = (int)dStrlen(subtext); pathLen = (strLen - endLen) ; dStrncpy(shapePath,mShape,pathLen); shapePath[pathLen] = '\0'; } S32 i = 0, count = stream->readInt(NumSequenceBits); for (; ireadSTString(); if (TS_IS_RELATIVE_SEQUENCES) { dSprintf(pathedSeq,90,"%s%s",shapePath,mSequence[i]); mSequence[i] = StringTable->insert(pathedSeq); } } while (i