DataPosition.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #include "DataPosition.h"
  2. #include "..\..\icommon\memfile.h"
  3. #include "..\..\..\common_h\core.h"
  4. #include "..\..\TextFile.h"
  5. #ifndef _XBOX
  6. #include "..\..\..\common_h\tinyxml\tinyxml.h"
  7. #endif
  8. #include "fieldlist.h"
  9. #include "..\..\..\Common_h\data_swizzle.h"
  10. //конструктор/деструктор
  11. DataPosition::DataPosition (FieldList* pMaster)
  12. {
  13. szName = NULL;
  14. szEditorName = NULL;
  15. Master = pMaster;
  16. Value = Vector(0, 0, 0);
  17. }
  18. DataPosition::~DataPosition ()
  19. {
  20. }
  21. //Получить значение (Текущее время, Коэфицент рандома[0..1])
  22. const Vector& DataPosition::GetValue ()
  23. {
  24. return Value;
  25. }
  26. //Установить значение
  27. void DataPosition::SetValue (const Vector& val)
  28. {
  29. Value = val;
  30. if (Master) Master->UpdateCache();
  31. }
  32. void DataPosition::Load (MemFile* File)
  33. {
  34. Vector vValue;
  35. File->ReadType(vValue.x);
  36. XSwizzleFloat(vValue.x);
  37. File->ReadType(vValue.y);
  38. XSwizzleFloat(vValue.y);
  39. File->ReadType(vValue.z);
  40. XSwizzleFloat(vValue.z);
  41. //api->Trace("Read position %3.2f, %3.2f, %3.2f", vValue.x, vValue.y, vValue.z);
  42. SetValue (vValue);
  43. //static char AttribueName[128];
  44. dword NameLength = 0;
  45. File->ReadType(NameLength);
  46. XSwizzleDWord(NameLength);
  47. Assert (NameLength < 128);
  48. //File->Read(AttribueName, NameLength);
  49. const char* AttribueName = File->GetPointerToString(NameLength);
  50. SetName (AttribueName, "a");
  51. if (Master) Master->UpdateCache();
  52. }
  53. void DataPosition::SetName (const char* szName, const char* szEditorName)
  54. {
  55. //api->Trace("DataPosition::SetName - '%s'", szName);
  56. this->szName = szName;
  57. this->szEditorName = szEditorName;
  58. }
  59. const char* DataPosition::GetName ()
  60. {
  61. return szName;
  62. }
  63. void DataPosition::Write (MemFile* File)
  64. {
  65. Vector vValue = GetValue();
  66. //api->Trace("Write position %3.2f, %3.2f, %3.2f", vValue.x, vValue.y, vValue.z);
  67. File->WriteType(vValue.x);
  68. File->WriteType(vValue.y);
  69. File->WriteType(vValue.z);
  70. //save name
  71. DWORD NameLength = crt_strlen(szName);
  72. DWORD NameLengthPlusZero = NameLength+1;
  73. File->WriteType(NameLengthPlusZero);
  74. Assert (NameLength < 128);
  75. File->Write(szName, NameLength);
  76. File->WriteZeroByte();
  77. }
  78. const char* DataPosition::GetEditorName ()
  79. {
  80. return szEditorName;
  81. }
  82. #ifndef _XBOX
  83. void DataPosition::WriteXML (TextFile* xmlFile, dword level)
  84. {
  85. xmlFile->Write((level+1), "<Name val = \"%s\" />\n", szName);
  86. xmlFile->Write((level+1), "<Value_x val = \"%f\" />\n", GetValue().x);
  87. xmlFile->Write((level+1), "<Value_y val = \"%f\" />\n", GetValue().y);
  88. xmlFile->Write((level+1), "<Value_z val = \"%f\" />\n", GetValue().z);
  89. }
  90. void DataPosition::LoadXML (TiXmlElement* root)
  91. {
  92. TiXmlElement* name = root->FirstChildElement("Name");
  93. TiXmlElement* value_x = root->FirstChildElement("Value_x");
  94. TiXmlElement* value_y = root->FirstChildElement("Value_y");
  95. TiXmlElement* value_z = root->FirstChildElement("Value_z");
  96. if (name)
  97. {
  98. SetName (name->Attribute("val"), "a");
  99. }
  100. Vector vl = 0.0f;
  101. if (value_x)
  102. {
  103. vl.x = (float)atof (value_x->Attribute("val"));
  104. }
  105. if (value_y)
  106. {
  107. vl.y = (float)atof (value_y->Attribute("val"));
  108. }
  109. if (value_z)
  110. {
  111. vl.z = (float)atof (value_z->Attribute("val"));
  112. }
  113. SetValue(vl);
  114. }
  115. #endif