DataFloat.cpp 2.2 KB

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