| 786 | //----------------------------------------------------------------------------- |
| 787 | |
| 788 | void Taml::compileDynamicFields(TamlWriteNode* pTamlWriteNode) |
| 789 | { |
| 790 | // Debug Profiling. |
| 791 | PROFILE_SCOPE(Taml_CompileDynamicFields); |
| 792 | |
| 793 | // Sanity! |
| 794 | AssertFatal(pTamlWriteNode != NULL, "Cannot compile dynamic fields on a NULL node."); |
| 795 | AssertFatal(pTamlWriteNode->mpSimObject != NULL, "Cannot compile dynamic fields on a node with no object."); |
| 796 | |
| 797 | // Fetch object. |
| 798 | SimObject* pSimObject = pTamlWriteNode->mpSimObject; |
| 799 | |
| 800 | // Fetch field dictionary. |
| 801 | SimFieldDictionary* pFieldDictionary = pSimObject->getFieldDictionary(); |
| 802 | |
| 803 | // Ignore if not writing dynamic fields. |
| 804 | if (!pFieldDictionary || !pSimObject->getCanSaveDynamicFields()) |
| 805 | return; |
| 806 | |
| 807 | // Fetch field list. |
| 808 | const AbstractClassRep::FieldList& fieldList = pSimObject->getFieldList(); |
| 809 | |
| 810 | // Fetch field count. |
| 811 | const U32 fieldCount = fieldList.size(); |
| 812 | |
| 813 | Vector<SimFieldDictionary::Entry*> dynamicFieldList(__FILE__, __LINE__); |
| 814 | |
| 815 | // Ensure the dynamic field doesn't conflict with static field. |
| 816 | for (U32 hashIndex = 0; hashIndex < SimFieldDictionary::HashTableSize; ++hashIndex) |
| 817 | { |
| 818 | for (SimFieldDictionary::Entry* pEntry = pFieldDictionary->mHashTable[hashIndex]; pEntry; pEntry = pEntry->next) |
| 819 | { |
| 820 | // Iterate static fields. |
| 821 | U32 fieldIndex; |
| 822 | for (fieldIndex = 0; fieldIndex < fieldCount; ++fieldIndex) |
| 823 | { |
| 824 | if (fieldList[fieldIndex].pFieldname == pEntry->slotName) |
| 825 | break; |
| 826 | } |
| 827 | |
| 828 | // Skip if found. |
| 829 | if (fieldIndex != (U32)fieldList.size()) |
| 830 | continue; |
| 831 | |
| 832 | // Skip if not writing field. |
| 833 | if (!pSimObject->writeField(pEntry->slotName, pEntry->value)) |
| 834 | continue; |
| 835 | |
| 836 | dynamicFieldList.push_back(pEntry); |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | // Sort Entries to prevent version control conflicts |
| 841 | if (dynamicFieldList.size() > 1) |
| 842 | dQsort(dynamicFieldList.address(), dynamicFieldList.size(), sizeof(SimFieldDictionary::Entry*), compareFieldEntries); |
| 843 | |
| 844 | // Save the fields. |
| 845 | for (Vector<SimFieldDictionary::Entry*>::iterator entryItr = dynamicFieldList.begin(); entryItr != dynamicFieldList.end(); ++entryItr) |
nothing calls this directly
no test coverage detected