tsDump.cpp

Engine/source/ts/tsDump.cpp

More...

Public Defines

define
dumpLine(buffer) {str = buffer; stream.write((int)(str),str);}

Detailed Description

Public Defines

dumpLine(buffer) {str = buffer; stream.write((int)(str),str);}
  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "platform/platform.h"
 25
 26#include "ts/tsShapeInstance.h"
 27#include "ts/tsMaterialList.h"
 28#include "core/strings/stringFunctions.h"
 29
 30
 31//-------------------------------------------------------------------------------------
 32// Dump shape structure:
 33//-------------------------------------------------------------------------------------
 34
 35#define dumpLine(buffer) {str = buffer; stream.write((int)dStrlen(str),str);}
 36
 37void TSShapeInstance::dumpNode(Stream & stream ,S32 level, S32 nodeIndex, Vector<S32> & detailSizes)
 38{
 39   if (nodeIndex < 0)
 40      return;
 41
 42   // limit level to prevent overflow
 43   if (level > 160)
 44      level = 160;
 45
 46   S32 i;
 47   const char * str;
 48   char space[512];
 49   for (i = 0; i < level*3; i++)
 50      space[i] = ' ';
 51   space[level*3] = '\0';
 52
 53   const char *nodeName = "";
 54   const TSShape::Node & node = mShape->nodes[nodeIndex];
 55   if (node.nameIndex != -1)
 56     nodeName = mShape->getName(node.nameIndex);
 57   dumpLine(avar("%s%s", space, nodeName));
 58
 59   // find all the objects that hang off this node...
 60   Vector<ObjectInstance*> objectList;
 61   for (i=0; i<mMeshObjects.size(); i++)
 62      if (mMeshObjects[i].nodeIndex == nodeIndex)
 63         objectList.push_back(&mMeshObjects[i]);
 64
 65   if (objectList.size() == 0)
 66      dumpLine("\r\n");
 67
 68   S32 nodeNameLen = dStrlen(nodeName);
 69   S32 spaceCount = -1;
 70   for (S32 j=0;j<objectList.size(); j++)
 71   {
 72      // should be a dynamic cast, but MSVC++ has problems with this...
 73      MeshObjectInstance * obj = (MeshObjectInstance *)(objectList[j]);
 74      if (!obj)
 75         continue;
 76
 77      // object name
 78      const char *objectName = "";
 79      if (obj->object->nameIndex!=-1)
 80         objectName = mShape->getName(obj->object->nameIndex);
 81
 82      // more spaces if this is the second object on this node
 83      if (spaceCount>0)
 84      {
 85         char buf[2048];
 86         dMemset(buf,' ',spaceCount);
 87         buf[spaceCount] = '\0';
 88         dumpLine(buf);
 89      }
 90
 91      // dump object name
 92      dumpLine(avar(" --> Object %s with following details: ",objectName));
 93
 94      // dump object detail levels
 95      for (S32 k=0; k<obj->object->numMeshes; k++)
 96      {
 97         S32 f = obj->object->startMeshIndex;
 98         if (mShape->meshes[f+k])
 99            dumpLine(avar(" %i",detailSizes[k]));
100      }
101
102      dumpLine("\r\n");
103
104      // how many spaces should we prepend if we have another object on this node
105      if (spaceCount<0)
106         spaceCount = (S32)(dStrlen(space) + nodeNameLen);
107
108      if(spaceCount > 2000)
109         spaceCount = 2000;
110   }
111
112   // search for children
113   for (S32 k=nodeIndex+1; k<mShape->nodes.size(); k++)
114   {
115      if (mShape->nodes[k].parentIndex == nodeIndex)
116         // this is our child
117         dumpNode(stream, level+1, k, detailSizes);
118   }
119}
120
121void TSShapeInstance::dump(Stream & stream)
122{
123   S32 i,j,ss,od,sz;
124   const char * name;
125   const char * str;
126
127   dumpLine("\r\nShape Hierarchy:\r\n");
128
129   dumpLine("\r\n   Details:\r\n");
130
131   for (i=0; i<mShape->details.size(); i++)
132   {
133      const TSDetail & detail = mShape->details[i];
134      name = mShape->getName(detail.nameIndex);
135      ss = detail.subShapeNum;
136      od = detail.objectDetailNum;
137      sz = (S32)detail.size;
138      if (ss >= 0)
139      {
140         dumpLine(avar("      %s, Subtree %i, objectDetail %i, size %i\r\n",name,ss,od,sz));
141      }
142      else
143      {
144         dumpLine(avar("      %s, AutoBillboard, size %i\r\n", name, sz));
145      }
146   }
147
148   dumpLine("\r\n   Subtrees:\r\n");
149
150   for (i=0; i<mShape->subShapeFirstNode.size(); i++)
151   {
152      S32 a = mShape->subShapeFirstNode[i];
153      S32 b = a + mShape->subShapeNumNodes[i];
154      dumpLine(avar("      Subtree %i\r\n",i));
155
156      // compute detail sizes for each subshape
157      Vector<S32> detailSizes;
158      for (S32 l=0;l<mShape->details.size(); l++)
159      {
160          if ((mShape->details[l].subShapeNum==<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1aa42a9a9cb6e2b93d7f825c395af871bf">i</a>) || (mShape->details[l].subShapeNum==-1))
161              detailSizes.push_back((S32)mShape->details[l].size);
162      }
163
164      for (j=<a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a>; j<b; j++)
165      {
166          const TSNode & node = mShape->nodes[j];
167          // if the node has a parent, it'll get dumped via the parent
168          if (node.parentIndex<0)
169              dumpNode(stream,3,j,detailSizes);
170      }
171   }
172
173   bool foundSkin = false;
174   for (i=0; i<mShape->objects.size(); i++)
175   {
176      TSShape::Object& currentObject = mShape->objects[i];
177
178      if (currentObject.nodeIndex<0) // must be a skin
179      {
180         if (!foundSkin)
181            dumpLine("\r\n   Skins:\r\n");
182         foundSkin=true;
183         const char * skinName = "";
184         S32 nameIndex = currentObject.nameIndex;
185         if (nameIndex>=0)
186            skinName = mShape->getName(nameIndex);
187         dumpLine(avar("      Skin %s with following details: ",skinName));
188         for (S32 num=0; num<currentObject.numMeshes; num++)
189         {
190            if (mShape->meshes[currentObject.startMeshIndex + num])
191               dumpLine(avar(" %i",(S32)mShape->details[num].size));
192         }
193         dumpLine("\r\n");
194      }
195   }
196   if (foundSkin)
197      dumpLine("\r\n");
198
199   dumpLine("\r\n   Sequences:\r\n");
200   for (i = 0; i < mShape->sequences.size(); i++)
201   {
202      const char *seqName = "(none)";
203      if (mShape->sequences[i].nameIndex != -1)
204        seqName = mShape->getName(mShape->sequences[i].nameIndex);
205      dumpLine(avar("      %3d: %s%s%s\r\n", i, seqName,
206         mShape->sequences[i].isCyclic() ? " (cyclic)" : "",
207         mShape->sequences[i].isBlend() ? " (blend)" : ""));
208   }
209
210   if (mShape->materialList)
211   {
212      TSMaterialList * ml = mShape->materialList;
213      dumpLine("\r\n   Material list:\r\n");
214      for (i=0; i<(S32)ml->size(); i++)
215      {
216         U32 flags = ml->getFlags(i);
217         const String& matName = ml->getMaterialName(i);
218         dumpLine(avar(
219            "   material #%i: '%s'%s.", i, matName.c_str(),
220            flags & (TSMaterialList::S_Wrap</a>|<a href="/coding/class/classtsmateriallist/#classtsmateriallist_1ac5b6fc96f66c62f4381d0ee006754267af580f30fa00dd8cd3ffabdafaaa3efb1">TSMaterialList::T_Wrap) ? "" : " not tiled")
221         );
222         if (flags & TSMaterialList::Translucent)
223         {
224            if (flags & TSMaterialList::Additive)
225               dumpLine("  Additive-translucent.")
226            else if (flags & TSMaterialList::Subtractive)
227               dumpLine("  Subtractive-translucent.")
228            else
229               dumpLine("  Translucent.")
230         }
231         dumpLine("\r\n");
232      }
233   }
234}
235
236