FieldList.cpp 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500
  1. #include "..\..\..\common_h\core.h"
  2. #include "fieldlist.h"
  3. #include "databool.h"
  4. #include "datacolor.h"
  5. #include "datafloat.h"
  6. #include "datagraph.h"
  7. #include "dataposition.h"
  8. #include "datauv.h"
  9. #include "datastring.h"
  10. #include "datasource.h"
  11. #include "..\ParticleProcessor\nameparser.h"
  12. #include "..\..\..\common_h\particles\iparticlemanager.h"
  13. #include "..\..\service\particleservice.h"
  14. extern ParticleService* PService;
  15. #ifndef _XBOX
  16. #include "..\..\..\common_h\tinyxml\tinyxml.h"
  17. #endif
  18. #include "..\..\TextFile.h"
  19. #include "..\..\..\Common_h\data_swizzle.h"
  20. FieldList::FieldList () : CachedGeomNames(_FL_),
  21. CachedForceFieldsID(_FL_)
  22. {
  23. for (dword n = 0; n < GUID_MAX; n++)
  24. {
  25. Fields[n].Type = FIELD_UNKNOWN;
  26. }
  27. pMaster = NULL;
  28. }
  29. void FieldList::SetMasterDataSource(DataSource* Master)
  30. {
  31. pMaster = Master;
  32. }
  33. FieldList::~FieldList ()
  34. {
  35. //нельзя тут делать DelAll надо тогда будет делать нормальный ctor копирования, и оператор присваивания
  36. //а без этого в массиве будут вызывать постоянно деструкторы и жопа
  37. //DelAll ();
  38. }
  39. #ifndef _XBOX
  40. void FieldList::CreateBoolFieldXML (TiXmlElement* root, DataDescripion* pDataDescriptor)
  41. {
  42. DataBool* Field = NEW DataBool(this);
  43. Field->LoadXML(root);
  44. FieldDesc pDesc;
  45. pDesc.MarkForDelete = false;
  46. pDesc.szName = Field->GetName();
  47. pDesc.HashValue = string::HashNoCase(pDesc.szName);
  48. pDesc.pPointer = Field;
  49. pDesc.Type = FIELD_BOOL;
  50. dword dwGUID = GetFieldGUIDByName(pDesc.szName, pDataDescriptor);
  51. if (dwGUID != 0xFFFFFFFF)
  52. {
  53. Fields[dwGUID] = pDesc;
  54. }
  55. //Fields.Add(pDesc);
  56. }
  57. void FieldList::CreateFloatFieldXML (TiXmlElement* root, DataDescripion* pDataDescriptor)
  58. {
  59. DataFloat* Field = NEW DataFloat(this);
  60. Field->LoadXML(root);
  61. FieldDesc pDesc;
  62. pDesc.MarkForDelete = false;
  63. pDesc.szName = Field->GetName();
  64. pDesc.HashValue = string::HashNoCase(pDesc.szName);
  65. pDesc.pPointer = Field;
  66. pDesc.Type = FIELD_FLOAT;
  67. dword dwGUID = GetFieldGUIDByName(pDesc.szName, pDataDescriptor);
  68. if (dwGUID != 0xFFFFFFFF)
  69. {
  70. Fields[dwGUID] = pDesc;
  71. }
  72. //Fields.Add(pDesc);
  73. }
  74. void FieldList::CreateGraphFieldXML (TiXmlElement* root, DataDescripion* pDataDescriptor)
  75. {
  76. //DataGraph* Field = NEW DataGraph(this);
  77. DataGraph* Field = PService->AllocateDataGraph(this);
  78. Field->LoadXML(root);
  79. FieldDesc pDesc;
  80. pDesc.MarkForDelete = false;
  81. pDesc.szName = Field->GetName();
  82. pDesc.HashValue = string::HashNoCase(pDesc.szName);
  83. pDesc.pPointer = Field;
  84. pDesc.Type = FIELD_GRAPH;
  85. dword dwGUID = GetFieldGUIDByName(pDesc.szName, pDataDescriptor);
  86. if (dwGUID != 0xFFFFFFFF)
  87. {
  88. Fields[dwGUID] = pDesc;
  89. }
  90. //Fields.Add(pDesc);
  91. }
  92. void FieldList::CreatePositionFieldXML (TiXmlElement* root, DataDescripion* pDataDescriptor)
  93. {
  94. DataPosition* Field = NEW DataPosition(this);
  95. Field->LoadXML(root);
  96. FieldDesc pDesc;
  97. pDesc.MarkForDelete = false;
  98. pDesc.szName = Field->GetName();
  99. pDesc.HashValue = string::HashNoCase(pDesc.szName);
  100. pDesc.pPointer = Field;
  101. pDesc.Type = FIELD_POSITION;
  102. dword dwGUID = GetFieldGUIDByName(pDesc.szName, pDataDescriptor);
  103. if (dwGUID != 0xFFFFFFFF)
  104. {
  105. Fields[dwGUID] = pDesc;
  106. }
  107. //Fields.Add(pDesc);
  108. }
  109. void FieldList::CreateStringFieldXML (TiXmlElement* root, DataDescripion* pDataDescriptor)
  110. {
  111. DataString* Field = NEW DataString(this);
  112. Field->LoadXML(root);
  113. FieldDesc pDesc;
  114. pDesc.MarkForDelete = false;
  115. pDesc.szName = Field->GetName();
  116. pDesc.HashValue = string::HashNoCase(pDesc.szName);
  117. pDesc.pPointer = Field;
  118. pDesc.Type = FIELD_STRING;
  119. dword dwGUID = GetFieldGUIDByName(pDesc.szName, pDataDescriptor);
  120. if (dwGUID != 0xFFFFFFFF)
  121. {
  122. Fields[dwGUID] = pDesc;
  123. }
  124. //Fields.Add(pDesc);
  125. }
  126. void FieldList::CreateUVFieldXML (TiXmlElement* root, DataDescripion* pDataDescriptor)
  127. {
  128. DataUV* Field = NEW DataUV(this);
  129. Field->LoadXML(root);
  130. FieldDesc pDesc;
  131. pDesc.MarkForDelete = false;
  132. pDesc.szName = Field->GetName();
  133. pDesc.HashValue = string::HashNoCase(pDesc.szName);
  134. pDesc.pPointer = Field;
  135. pDesc.Type = FIELD_UV;
  136. dword dwGUID = GetFieldGUIDByName(pDesc.szName, pDataDescriptor);
  137. if (dwGUID != 0xFFFFFFFF)
  138. {
  139. Fields[dwGUID] = pDesc;
  140. }
  141. //Fields.Add(pDesc);
  142. }
  143. void FieldList::CreateColorFieldXML (TiXmlElement* root, DataDescripion* pDataDescriptor)
  144. {
  145. DataColor* Field = NEW DataColor(this);
  146. Field->LoadXML(root);
  147. FieldDesc pDesc;
  148. pDesc.MarkForDelete = false;
  149. pDesc.szName = Field->GetName();
  150. pDesc.HashValue = string::HashNoCase(pDesc.szName);
  151. pDesc.pPointer = Field;
  152. pDesc.Type = FIELD_COLOR;
  153. dword dwGUID = GetFieldGUIDByName(pDesc.szName, pDataDescriptor);
  154. if (dwGUID != 0xFFFFFFFF)
  155. {
  156. Fields[dwGUID] = pDesc;
  157. }
  158. //Fields.Add(pDesc);
  159. }
  160. void FieldList::LoadXML (TiXmlElement* root, DataDescripion* pDataDescriptor)
  161. {
  162. for(TiXmlElement* child = root->FirstChildElement(); child; child = child->NextSiblingElement())
  163. {
  164. string NodeName = child->Value();
  165. string NodeVal = child->Attribute("val");
  166. if (NodeName != "Field") continue;
  167. if (NodeVal == "FIELD_BOOL")
  168. {
  169. CreateBoolFieldXML (child, pDataDescriptor);
  170. }
  171. if (NodeVal == "FIELD_FLOAT")
  172. {
  173. CreateFloatFieldXML (child, pDataDescriptor);
  174. }
  175. if (NodeVal == "FIELD_GRAPH")
  176. {
  177. CreateGraphFieldXML (child, pDataDescriptor);
  178. }
  179. if (NodeVal == "FIELD_POSITION")
  180. {
  181. CreatePositionFieldXML (child, pDataDescriptor);
  182. }
  183. if (NodeVal == "FIELD_STRING")
  184. {
  185. CreateStringFieldXML (child, pDataDescriptor);
  186. }
  187. if (NodeVal == "FIELD_UV")
  188. {
  189. CreateUVFieldXML (child, pDataDescriptor);
  190. }
  191. if (NodeVal == "FIELD_COLOR")
  192. {
  193. CreateColorFieldXML (child, pDataDescriptor);
  194. }
  195. }
  196. }
  197. #endif
  198. void FieldList::Load (MemFile* File, DataDescripion* pDataDescriptor)
  199. {
  200. dword DataFieldsCount = 0;
  201. File->ReadType(DataFieldsCount);
  202. XSwizzleDWord(DataFieldsCount);
  203. for (DWORD n = 0; n < DataFieldsCount; n++)
  204. {
  205. FieldType fldType = FIELD_UNKNOWN;
  206. File->ReadType(fldType);
  207. fldType = (FieldType)SwizzleDWord(fldType);
  208. switch (fldType)
  209. {
  210. case FIELD_BOOL:
  211. {
  212. //api->Trace ("Particles info: BOOL field");
  213. CreateBoolField (File, pDataDescriptor);
  214. break;
  215. }
  216. case FIELD_FLOAT:
  217. {
  218. //api->Trace ("Particles info: FLOAT field");
  219. CreateFloatField (File, pDataDescriptor);
  220. break;
  221. }
  222. case FIELD_GRAPH:
  223. {
  224. //api->Trace ("Particles info: GRAPH field");
  225. CreateGraphField (File, pDataDescriptor);
  226. break;
  227. }
  228. case FIELD_POSITION:
  229. {
  230. //api->Trace ("Particles info: POSITION field");
  231. CreatePositionField (File, pDataDescriptor);
  232. break;
  233. }
  234. case FIELD_STRING:
  235. {
  236. //api->Trace ("Particles info: STRING field");
  237. CreateStringField (File, pDataDescriptor);
  238. break;
  239. }
  240. case FIELD_UV:
  241. {
  242. //api->Trace ("Particles info: UV field");
  243. CreateUVField (File, pDataDescriptor);
  244. break;
  245. }
  246. case FIELD_COLOR:
  247. {
  248. //api->Trace ("Particles info: COLOR field");
  249. CreateColorField (File, pDataDescriptor);
  250. break;
  251. }
  252. default:
  253. {
  254. throw ("Particles: Unknown field type !!!!");
  255. }
  256. } //switch
  257. } // for all fileds
  258. }
  259. void FieldList::CreateEmptyBoolField (dword guid, const char* Name, const char* EditorName, bool def_value)
  260. {
  261. DataBool* Field = NEW DataBool(this);
  262. Field->SetName(Name, EditorName);
  263. Field->SetValue(def_value);
  264. FieldDesc pDesc;
  265. pDesc.dwGUID = guid;
  266. pDesc.MarkForDelete = false;
  267. pDesc.szName = Field->GetName();
  268. pDesc.szEditorName = EditorName;
  269. pDesc.HashValue = string::HashNoCase(pDesc.szName);
  270. pDesc.pPointer = Field;
  271. pDesc.Type = FIELD_BOOL;
  272. //Fields.Add(pDesc);
  273. Fields[guid] = pDesc;
  274. }
  275. void FieldList::CreateEmptyFloatField (dword guid, const char* Name, const char* EditorName, float def_value)
  276. {
  277. DataFloat* Field = NEW DataFloat(this);
  278. Field->SetName(Name, EditorName);
  279. Field->SetValue(def_value);
  280. FieldDesc pDesc;
  281. pDesc.dwGUID = guid;
  282. pDesc.MarkForDelete = false;
  283. pDesc.szName = Field->GetName();
  284. pDesc.szEditorName = EditorName;
  285. pDesc.HashValue = string::HashNoCase(pDesc.szName);
  286. pDesc.pPointer = Field;
  287. pDesc.Type = FIELD_FLOAT;
  288. //Fields.Add(pDesc);
  289. Fields[guid] = pDesc;
  290. }
  291. void FieldList::CreateEmptyGraphField (dword guid, const char* Name, const char* EditorName, float def_value_min, float def_value_max)
  292. {
  293. //DataGraph* Field = NEW DataGraph(this);
  294. DataGraph* Field = PService->AllocateDataGraph(this);
  295. Field->SetName(Name, EditorName);
  296. if (crt_stricmp (PARTICLE_COLORMULTIPLY, Name) == 0)
  297. {
  298. Field->SetDefaultValue(1.0f, 1.0f);
  299. } else
  300. {
  301. Field->SetDefaultValue(def_value_max, def_value_min);
  302. }
  303. FieldDesc pDesc;
  304. pDesc.dwGUID = guid;
  305. pDesc.MarkForDelete = false;
  306. pDesc.szName = Field->GetName();
  307. pDesc.szEditorName = EditorName;
  308. pDesc.HashValue = string::HashNoCase(pDesc.szName);
  309. pDesc.pPointer = Field;
  310. pDesc.Type = FIELD_GRAPH;
  311. //Fields.Add(pDesc);
  312. Fields[guid] = pDesc;
  313. }
  314. void FieldList::CreateEmptyPositionField (dword guid, const char* Name, const char* EditorName, const Vector& def_value)
  315. {
  316. DataPosition* Field = NEW DataPosition(this);
  317. Field->SetName(Name, EditorName);
  318. Field->SetValue(def_value);
  319. FieldDesc pDesc;
  320. pDesc.dwGUID = guid;
  321. pDesc.MarkForDelete = false;
  322. pDesc.szName = Field->GetName();
  323. pDesc.szEditorName = EditorName;
  324. pDesc.HashValue = string::HashNoCase(pDesc.szName);
  325. pDesc.pPointer = Field;
  326. pDesc.Type = FIELD_POSITION;
  327. //Fields.Add(pDesc);
  328. Fields[guid] = pDesc;
  329. }
  330. void FieldList::CreateEmptyStringField (dword guid, const char* Name, const char* EditorName, const char* def_value)
  331. {
  332. DataString* Field = NEW DataString(this);
  333. Field->SetName(Name, EditorName);
  334. Field->SetValue(def_value);
  335. FieldDesc pDesc;
  336. pDesc.dwGUID = guid;
  337. pDesc.MarkForDelete = false;
  338. pDesc.szName = Field->GetName();
  339. pDesc.szEditorName = EditorName;
  340. pDesc.HashValue = string::HashNoCase(pDesc.szName);
  341. pDesc.pPointer = Field;
  342. pDesc.Type = FIELD_STRING;
  343. //Fields.Add(pDesc);
  344. Fields[guid] = pDesc;
  345. }
  346. void FieldList::CreateEmptyUVField (dword guid, const char* Name, const char* EditorName)
  347. {
  348. DataUV* Field = NEW DataUV(this);
  349. Field->SetName(Name, EditorName);
  350. Field->SetValues(&Vector4(0.0f, 0.0f, 1.0f, 1.0f), 1);
  351. FieldDesc pDesc;
  352. pDesc.dwGUID = guid;
  353. pDesc.MarkForDelete = false;
  354. pDesc.szName = Field->GetName();
  355. pDesc.szEditorName = EditorName;
  356. pDesc.HashValue = string::HashNoCase(pDesc.szName);
  357. pDesc.pPointer = Field;
  358. pDesc.Type = FIELD_UV;
  359. //Fields.Add(pDesc);
  360. Fields[guid] = pDesc;
  361. }
  362. void FieldList::CreateEmptyColorField (dword guid, const char* Name, const char* EditorName, DWORD def_value)
  363. {
  364. DataColor* Field = NEW DataColor(this);
  365. Field->SetName(Name, EditorName);
  366. ColorVertex defVal[2];
  367. defVal[0].MinValue = dword(def_value);
  368. defVal[0].MaxValue = dword(def_value);
  369. defVal[1].MinValue = dword(def_value);
  370. defVal[1].MaxValue = dword(def_value);
  371. Field->SetValues(defVal, 2);
  372. FieldDesc pDesc;
  373. pDesc.dwGUID = guid;
  374. pDesc.MarkForDelete = false;
  375. pDesc.szName = Field->GetName();
  376. pDesc.szEditorName = EditorName;
  377. pDesc.HashValue = string::HashNoCase(pDesc.szName);
  378. pDesc.pPointer = Field;
  379. pDesc.Type = FIELD_COLOR;
  380. //Fields.Add(pDesc);
  381. Fields[guid] = pDesc;
  382. }
  383. void FieldList::CreateBoolField (MemFile* pMemFile, DataDescripion* pDataDescriptor)
  384. {
  385. DataBool* Field = NEW DataBool(this);
  386. Field->Load(pMemFile);
  387. FieldDesc pDesc;
  388. pDesc.MarkForDelete = false;
  389. pDesc.szName = Field->GetName();
  390. pDesc.HashValue = string::HashNoCase(pDesc.szName);
  391. pDesc.pPointer = Field;
  392. pDesc.Type = FIELD_BOOL;
  393. dword dwGUID = GetFieldGUIDByName(pDesc.szName, pDataDescriptor);
  394. if (dwGUID != 0xFFFFFFFF)
  395. {
  396. Fields[dwGUID] = pDesc;
  397. } else
  398. {
  399. delete Field;
  400. }
  401. //Fields.Add(pDesc);
  402. }
  403. void FieldList::CreateFloatField (MemFile* pMemFile, DataDescripion* pDataDescriptor)
  404. {
  405. DataFloat* Field = NEW DataFloat(this);
  406. Field->Load(pMemFile);
  407. FieldDesc pDesc;
  408. pDesc.MarkForDelete = false;
  409. pDesc.szName = Field->GetName();
  410. pDesc.HashValue = string::HashNoCase(pDesc.szName);
  411. pDesc.pPointer = Field;
  412. pDesc.Type = FIELD_FLOAT;
  413. dword dwGUID = GetFieldGUIDByName(pDesc.szName, pDataDescriptor);
  414. if (dwGUID != 0xFFFFFFFF)
  415. {
  416. Fields[dwGUID] = pDesc;
  417. } else
  418. {
  419. delete Field;
  420. }
  421. //Fields.Add(pDesc);
  422. }
  423. void FieldList::CreateGraphField (MemFile* pMemFile, DataDescripion* pDataDescriptor)
  424. {
  425. //DataGraph* Field = NEW DataGraph(this);
  426. DataGraph* Field = PService->AllocateDataGraph(this);
  427. Field->Load(pMemFile);
  428. FieldDesc pDesc;
  429. pDesc.MarkForDelete = false;
  430. pDesc.szName = Field->GetName();
  431. pDesc.HashValue = string::HashNoCase(pDesc.szName);
  432. pDesc.pPointer = Field;
  433. pDesc.Type = FIELD_GRAPH;
  434. dword dwGUID = GetFieldGUIDByName(pDesc.szName, pDataDescriptor);
  435. if (dwGUID != 0xFFFFFFFF)
  436. {
  437. Fields[dwGUID] = pDesc;
  438. } else
  439. {
  440. delete Field;
  441. }
  442. //Fields.Add(pDesc);
  443. }
  444. void FieldList::CreatePositionField (MemFile* pMemFile, DataDescripion* pDataDescriptor)
  445. {
  446. DataPosition* Field = NEW DataPosition(this);
  447. Field->Load(pMemFile);
  448. FieldDesc pDesc;
  449. pDesc.MarkForDelete = false;
  450. pDesc.szName = Field->GetName();
  451. pDesc.HashValue = string::HashNoCase(pDesc.szName);
  452. pDesc.pPointer = Field;
  453. pDesc.Type = FIELD_POSITION;
  454. dword dwGUID = GetFieldGUIDByName(pDesc.szName, pDataDescriptor);
  455. if (dwGUID != 0xFFFFFFFF)
  456. {
  457. Fields[dwGUID] = pDesc;
  458. } else
  459. {
  460. delete Field;
  461. }
  462. //Fields.Add(pDesc);
  463. }
  464. void FieldList::CreateStringField (MemFile* pMemFile, DataDescripion* pDataDescriptor)
  465. {
  466. DataString* Field = NEW DataString(this);
  467. Field->Load(pMemFile);
  468. FieldDesc pDesc;
  469. pDesc.MarkForDelete = false;
  470. pDesc.szName = Field->GetName();
  471. pDesc.HashValue = string::HashNoCase(pDesc.szName);
  472. pDesc.pPointer = Field;
  473. pDesc.Type = FIELD_STRING;
  474. dword dwGUID = GetFieldGUIDByName(pDesc.szName, pDataDescriptor);
  475. if (dwGUID != 0xFFFFFFFF)
  476. {
  477. Fields[dwGUID] = pDesc;
  478. } else
  479. {
  480. delete Field;
  481. }
  482. //Fields.Add(pDesc);
  483. }
  484. void FieldList::CreateUVField (MemFile* pMemFile, DataDescripion* pDataDescriptor)
  485. {
  486. DataUV* Field = NEW DataUV(this);
  487. Field->Load(pMemFile);
  488. FieldDesc pDesc;
  489. pDesc.MarkForDelete = false;
  490. pDesc.szName = Field->GetName();
  491. pDesc.HashValue = string::HashNoCase(pDesc.szName);
  492. pDesc.pPointer = Field;
  493. pDesc.Type = FIELD_UV;
  494. dword dwGUID = GetFieldGUIDByName(pDesc.szName, pDataDescriptor);
  495. if (dwGUID != 0xFFFFFFFF)
  496. {
  497. Fields[dwGUID] = pDesc;
  498. } else
  499. {
  500. delete Field;
  501. }
  502. //Fields.Add(pDesc);
  503. }
  504. void FieldList::CreateColorField (MemFile* pMemFile, DataDescripion* pDataDescriptor)
  505. {
  506. DataColor* Field = NEW DataColor(this);
  507. Field->Load(pMemFile);
  508. FieldDesc pDesc;
  509. pDesc.MarkForDelete = false;
  510. pDesc.szName = Field->GetName();
  511. pDesc.HashValue = string::HashNoCase(pDesc.szName);
  512. pDesc.pPointer = Field;
  513. pDesc.Type = FIELD_COLOR;
  514. dword dwGUID = GetFieldGUIDByName(pDesc.szName, pDataDescriptor);
  515. if (dwGUID != 0xFFFFFFFF)
  516. {
  517. Fields[dwGUID] = pDesc;
  518. } else
  519. {
  520. delete Field;
  521. }
  522. //Fields.Add(pDesc);
  523. }
  524. void FieldList::DelAll ()
  525. {
  526. for (DWORD n = 0; n < GUID_MAX; n++)
  527. {
  528. if (Fields[n].Type == FIELD_UNKNOWN) continue;
  529. DeleteFieldData (Fields[n]);
  530. Fields[n].Type = FIELD_UNKNOWN;
  531. } // loop
  532. //Fields.DelAll();
  533. }
  534. DataColor* FieldList::FindColorByGUID (dword GUID)
  535. {
  536. if (GUID >= GUID_MAX) return NULL;
  537. if (Fields[GUID].Type != FIELD_COLOR)
  538. {
  539. return NULL;
  540. }
  541. return ((DataColor*)Fields[GUID].pPointer);
  542. /*
  543. for (DWORD n = 0; n < Fields.Size(); n++)
  544. {
  545. if (Fields[n].Type == FIELD_COLOR)
  546. {
  547. if (GUID == Fields[n].dwGUID)
  548. {
  549. return ((DataColor*)Fields[n].pPointer);
  550. }
  551. }
  552. }
  553. return NULL;
  554. */
  555. }
  556. /*
  557. DataColor* FieldList::FindColor (const char* AttrName)
  558. {
  559. DWORD SearchHash = string::HashNoCase(AttrName);
  560. for (DWORD n = 0; n < GUID_MAX; n++)
  561. {
  562. if (Fields[n].Type == FIELD_COLOR)
  563. {
  564. if (SearchHash == Fields[n].HashValue)
  565. {
  566. if (crt_stricmp (Fields[n].szName, AttrName) == 0)
  567. {
  568. return ((DataColor*)Fields[n].pPointer);
  569. }
  570. }
  571. }
  572. }
  573. return NULL;
  574. }
  575. */
  576. DataBool* FieldList::FindBoolByGUID (dword GUID)
  577. {
  578. if (GUID >= GUID_MAX) return NULL;
  579. if (Fields[GUID].Type != FIELD_BOOL)
  580. {
  581. return NULL;
  582. }
  583. return ((DataBool*)Fields[GUID].pPointer);
  584. /*
  585. for (DWORD n = 0; n < Fields.Size(); n++)
  586. {
  587. if (Fields[n].Type == FIELD_BOOL)
  588. {
  589. if (GUID == Fields[n].dwGUID)
  590. {
  591. return ((DataBool*)Fields[n].pPointer);
  592. }
  593. }
  594. }
  595. return NULL;
  596. */
  597. }
  598. /*
  599. DataBool* FieldList::FindBool (const char* AttrName)
  600. {
  601. DWORD SearchHash = string::HashNoCase(AttrName);
  602. for (DWORD n = 0; n < GUID_MAX; n++)
  603. {
  604. if (Fields[n].Type == FIELD_BOOL)
  605. {
  606. if (SearchHash == Fields[n].HashValue)
  607. {
  608. if (crt_stricmp (Fields[n].szName, AttrName) == 0)
  609. {
  610. return ((DataBool*)Fields[n].pPointer);
  611. }
  612. }
  613. }
  614. }
  615. return NULL;
  616. }
  617. */
  618. DataFloat* FieldList::FindFloatByGUID (dword GUID)
  619. {
  620. if (GUID >= GUID_MAX) return NULL;
  621. if (Fields[GUID].Type != FIELD_FLOAT)
  622. {
  623. return NULL;
  624. }
  625. return ((DataFloat*)Fields[GUID].pPointer);
  626. /*
  627. for (DWORD n = 0; n < Fields.Size(); n++)
  628. {
  629. if (Fields[n].Type == FIELD_FLOAT)
  630. {
  631. if (GUID == Fields[n].dwGUID)
  632. {
  633. return ((DataFloat*)Fields[n].pPointer);
  634. }
  635. }
  636. }
  637. return NULL;
  638. */
  639. }
  640. /*
  641. DataFloat* FieldList::FindFloat (const char* AttrName)
  642. {
  643. DWORD SearchHash = string::HashNoCase(AttrName);
  644. for (DWORD n = 0; n < GUID_MAX; n++)
  645. {
  646. if (Fields[n].Type == FIELD_FLOAT)
  647. {
  648. if (SearchHash == Fields[n].HashValue)
  649. {
  650. if (crt_stricmp (Fields[n].szName, AttrName) == 0)
  651. {
  652. return ((DataFloat*)Fields[n].pPointer);
  653. }
  654. }
  655. }
  656. }
  657. return NULL;
  658. }
  659. */
  660. DataGraph* FieldList::FindGraphByGUID (dword GUID)
  661. {
  662. if (GUID >= GUID_MAX) return NULL;
  663. if (Fields[GUID].Type != FIELD_GRAPH)
  664. {
  665. return NULL;
  666. }
  667. return ((DataGraph*)Fields[GUID].pPointer);
  668. /*
  669. for (DWORD n = 0; n < Fields.Size(); n++)
  670. {
  671. if (Fields[n].Type == FIELD_GRAPH)
  672. {
  673. if (GUID == Fields[n].dwGUID)
  674. {
  675. return ((DataGraph*)Fields[n].pPointer);
  676. }
  677. }
  678. }
  679. return NULL;
  680. */
  681. }
  682. /*
  683. DataGraph* FieldList::FindGraph (const char* AttrName)
  684. {
  685. DWORD SearchHash = string::HashNoCase(AttrName);
  686. for (DWORD n = 0; n < GUID_MAX; n++)
  687. {
  688. if (Fields[n].Type == FIELD_GRAPH)
  689. {
  690. if (SearchHash == Fields[n].HashValue)
  691. {
  692. if (crt_stricmp (Fields[n].szName, AttrName) == 0)
  693. {
  694. return ((DataGraph*)Fields[n].pPointer);
  695. }
  696. }
  697. }
  698. }
  699. return NULL;
  700. }
  701. */
  702. DataString* FieldList::FindStringByGUID (dword GUID)
  703. {
  704. if (GUID >= GUID_MAX) return NULL;
  705. if (Fields[GUID].Type != FIELD_STRING)
  706. {
  707. return NULL;
  708. }
  709. return ((DataString*)Fields[GUID].pPointer);
  710. /*
  711. for (DWORD n = 0; n < Fields.Size(); n++)
  712. {
  713. if (Fields[n].Type == FIELD_STRING)
  714. {
  715. if (GUID == Fields[n].dwGUID)
  716. {
  717. return ((DataString*)Fields[n].pPointer);
  718. }
  719. }
  720. }
  721. return NULL;
  722. */
  723. }
  724. /*
  725. DataString* FieldList::FindString (const char* AttrName)
  726. {
  727. DWORD SearchHash = string::HashNoCase(AttrName);
  728. for (DWORD n = 0; n < GUID_MAX; n++)
  729. {
  730. if (Fields[n].Type == FIELD_STRING)
  731. {
  732. if (SearchHash == Fields[n].HashValue)
  733. {
  734. if (crt_stricmp (Fields[n].szName, AttrName) == 0)
  735. {
  736. return ((DataString*)Fields[n].pPointer);
  737. }
  738. }
  739. }
  740. }
  741. return NULL;
  742. }
  743. */
  744. DataPosition* FieldList::FindPositionByGUID (dword GUID)
  745. {
  746. if (GUID >= GUID_MAX) return NULL;
  747. if (Fields[GUID].Type != FIELD_POSITION)
  748. {
  749. return NULL;
  750. }
  751. return ((DataPosition*)Fields[GUID].pPointer);
  752. /*
  753. for (DWORD n = 0; n < Fields.Size(); n++)
  754. {
  755. if (Fields[n].Type == FIELD_POSITION)
  756. {
  757. if (GUID == Fields[n].dwGUID)
  758. {
  759. return ((DataPosition*)Fields[n].pPointer);
  760. }
  761. }
  762. }
  763. return NULL;
  764. */
  765. }
  766. /*
  767. DataPosition* FieldList::FindPosition (const char* AttrName)
  768. {
  769. DWORD SearchHash = string::HashNoCase(AttrName);
  770. for (DWORD n = 0; n < GUID_MAX; n++)
  771. {
  772. if (Fields[n].Type == FIELD_POSITION)
  773. {
  774. if (SearchHash == Fields[n].HashValue)
  775. {
  776. if (crt_stricmp (Fields[n].szName, AttrName) == 0)
  777. {
  778. return ((DataPosition*)Fields[n].pPointer);
  779. }
  780. }
  781. }
  782. }
  783. return NULL;
  784. }
  785. */
  786. DataUV* FieldList::FindUVByGUID (dword GUID)
  787. {
  788. if (GUID >= GUID_MAX) return NULL;
  789. if (Fields[GUID].Type != FIELD_UV)
  790. {
  791. return NULL;
  792. }
  793. return ((DataUV*)Fields[GUID].pPointer);
  794. /*
  795. for (DWORD n = 0; n < Fields.Size(); n++)
  796. {
  797. if (Fields[n].Type == FIELD_UV)
  798. {
  799. if (GUID == Fields[n].dwGUID)
  800. {
  801. return ((DataUV*)Fields[n].pPointer);
  802. }
  803. }
  804. }
  805. return NULL;
  806. */
  807. }
  808. /*
  809. DataUV* FieldList::FindUV (const char* AttrName)
  810. {
  811. DWORD SearchHash = string::HashNoCase(AttrName);
  812. for (DWORD n = 0; n < Fields.Size(); n++)
  813. {
  814. if (Fields[n].Type == FIELD_UV)
  815. {
  816. if (SearchHash == Fields[n].HashValue)
  817. {
  818. if (crt_stricmp (Fields[n].szName, AttrName) == 0)
  819. {
  820. return ((DataUV*)Fields[n].pPointer);
  821. }
  822. }
  823. }
  824. }
  825. return NULL;
  826. }
  827. */
  828. /*
  829. FieldList::FieldDesc* FieldList::FindField (const char* Name)
  830. {
  831. DWORD SearchHash = string::HashNoCase(Name);
  832. for (DWORD n = 0; n < Fields.Size(); n++)
  833. {
  834. if (SearchHash == Fields[n].HashValue)
  835. {
  836. if (crt_stricmp (Fields[n].szName, Name) == 0)
  837. {
  838. return &Fields[n];
  839. }
  840. }
  841. }
  842. return NULL;
  843. }
  844. */
  845. float FieldList::GetFloat (dword dwGUID, float def_value)
  846. {
  847. DataFloat* pFind = FindFloatByGUID(dwGUID);
  848. if (!pFind) return def_value;
  849. return pFind->GetValue();
  850. }
  851. int FieldList::GetFloatAsInt (dword dwGUID, int def_value)
  852. {
  853. float val = GetFloat(dwGUID, (float)def_value);
  854. return (int)val;
  855. }
  856. bool FieldList::GetBool (dword dwGUID, bool def_value)
  857. {
  858. DataBool* pFind = FindBoolByGUID(dwGUID);
  859. if (!pFind) return def_value;
  860. return pFind->GetValue();
  861. }
  862. const char* FieldList::GetString (dword dwGUID, const char* def_value)
  863. {
  864. DataString* pFind = FindStringByGUID(dwGUID);
  865. if (!pFind) return def_value;
  866. return pFind->GetValue();
  867. }
  868. const Vector& FieldList::GetPosition (dword dwGUID, const Vector& def_value)
  869. {
  870. DataPosition* pFind = FindPositionByGUID(dwGUID);
  871. if (!pFind) return def_value;
  872. return pFind->GetValue();
  873. }
  874. float FieldList::GetGraphVal (dword dwGUID, float Time, float LifeTime, float K_Rand, float def_value)
  875. {
  876. DataGraph* pFind = FindGraphByGUID(dwGUID);
  877. if (!pFind) return def_value;
  878. return pFind->GetValue(Time, LifeTime, K_Rand);
  879. }
  880. float FieldList::GetRandomGraphVal (dword dwGUID, float Time, float LifeTime, float def_value)
  881. {
  882. DataGraph* pFind = FindGraphByGUID(dwGUID);
  883. if (!pFind) return def_value;
  884. return pFind->GetRandomValue(Time, LifeTime);
  885. }
  886. DWORD FieldList::_GetFieldCount ()
  887. {
  888. return GUID_MAX;
  889. }
  890. const FieldList::FieldDesc& FieldList::_GetFieldByIndex (DWORD Index)
  891. {
  892. return Fields[Index];
  893. }
  894. dword FieldList::GetFieldGUIDByName (const char* name, DataDescripion* pDataDescriptor)
  895. {
  896. DWORD NeedFieldsCount = pDataDescriptor->GetFieldCount();
  897. for (DWORD n = 0; n < NeedFieldsCount; n++)
  898. {
  899. const char* NeedFieldName = pDataDescriptor->GetFieldName(n);
  900. if (crt_stricmp(NeedFieldName, name) == 0)
  901. {
  902. dword dwFieldGUID = pDataDescriptor->GetFieldGUID(n);
  903. return dwFieldGUID;
  904. }
  905. }
  906. return 0xFFFFFFFF;
  907. }
  908. void FieldList::Convert (DataDescripion* pDataDescriptor)
  909. {
  910. for (DWORD i = 0; i < GUID_MAX; i++)
  911. {
  912. Fields[i].MarkForDelete = true;
  913. }
  914. DWORD NeedFieldsCount = pDataDescriptor->GetFieldCount();
  915. for (DWORD n = 0; n < NeedFieldsCount; n++)
  916. {
  917. dword dwFieldGUID = pDataDescriptor->GetFieldGUID(n);
  918. const char* szEditorName = pDataDescriptor->GetFieldEditorName(n);
  919. const char* NeedFieldName = pDataDescriptor->GetFieldName(n);
  920. FieldType NeedFieldType = pDataDescriptor->GetFieldType(n);
  921. //FieldDesc* pDesc = FindField (NeedFieldName);
  922. FieldDesc* pDesc = NULL;
  923. if (dwFieldGUID < GUID_MAX)
  924. {
  925. if (Fields[dwFieldGUID].Type != FIELD_UNKNOWN)
  926. {
  927. pDesc = &Fields[dwFieldGUID];
  928. }
  929. }
  930. bool FieldExist = false;
  931. if (pDesc)
  932. {
  933. if (pDesc->Type == NeedFieldType)
  934. {
  935. //Если нашли поле и оно нужного типа, убираем пометку об удалении
  936. pDesc->MarkForDelete = false;
  937. FieldExist = true;
  938. pDesc->szEditorName = szEditorName;
  939. pDesc->dwGUID = dwFieldGUID;
  940. switch (NeedFieldType)
  941. {
  942. case FIELD_COLOR:
  943. ((DataColor*)pDesc->pPointer)->SetName(NeedFieldName, szEditorName);
  944. break;
  945. case FIELD_BOOL:
  946. ((DataBool*)pDesc->pPointer)->SetName(NeedFieldName, szEditorName);
  947. break;
  948. case FIELD_FLOAT:
  949. ((DataFloat*)pDesc->pPointer)->SetName(NeedFieldName, szEditorName);
  950. break;
  951. case FIELD_GRAPH:
  952. ((DataGraph*)pDesc->pPointer)->SetName(NeedFieldName, szEditorName);
  953. break;
  954. case FIELD_POSITION:
  955. ((DataPosition*)pDesc->pPointer)->SetName(NeedFieldName, szEditorName);
  956. break;
  957. case FIELD_UV:
  958. ((DataUV*)pDesc->pPointer)->SetName(NeedFieldName, szEditorName);
  959. break;
  960. case FIELD_STRING:
  961. ((DataString*)pDesc->pPointer)->SetName(NeedFieldName, szEditorName);
  962. break;
  963. default:
  964. throw ("Unknown Field type !!!");
  965. }
  966. }
  967. }
  968. //Если поле не существует, надо его создать...
  969. if (!FieldExist)
  970. {
  971. switch (NeedFieldType)
  972. {
  973. case FIELD_COLOR:
  974. CreateEmptyColorField(dwFieldGUID, NeedFieldName, szEditorName, 0xFFFFA030);
  975. break;
  976. case FIELD_BOOL:
  977. CreateEmptyBoolField(dwFieldGUID, NeedFieldName, szEditorName, false);
  978. break;
  979. case FIELD_FLOAT:
  980. CreateEmptyFloatField(dwFieldGUID, NeedFieldName, szEditorName, 0.0f);
  981. break;
  982. case FIELD_GRAPH:
  983. CreateEmptyGraphField(dwFieldGUID, NeedFieldName, szEditorName, 0.0f, 0.0f);
  984. break;
  985. case FIELD_POSITION:
  986. CreateEmptyPositionField(dwFieldGUID, NeedFieldName, szEditorName, Vector(0.0f));
  987. break;
  988. case FIELD_UV:
  989. CreateEmptyUVField(dwFieldGUID, NeedFieldName, szEditorName);
  990. break;
  991. case FIELD_STRING:
  992. CreateEmptyStringField(dwFieldGUID, NeedFieldName, szEditorName, "#empty#");
  993. break;
  994. default:
  995. throw ("Unknown Field type !!!");
  996. }
  997. }
  998. }
  999. for (i = 0; i < GUID_MAX; i++)
  1000. {
  1001. if (Fields[i].MarkForDelete)
  1002. {
  1003. if (Fields[i].Type == FIELD_UNKNOWN) continue;
  1004. DeleteFieldData (Fields[i]);
  1005. Fields[i].Type = FIELD_UNKNOWN;
  1006. //Fields.ExtractNoShift(i);
  1007. //i--;
  1008. }
  1009. }
  1010. }
  1011. void FieldList::DeleteFieldData (const FieldList::FieldDesc& pData)
  1012. {
  1013. FieldType fldType = pData.Type;
  1014. switch (fldType)
  1015. {
  1016. case FIELD_BOOL:
  1017. {
  1018. delete ((DataBool*)pData.pPointer);
  1019. break;
  1020. }
  1021. case FIELD_FLOAT:
  1022. {
  1023. delete ((DataFloat*)pData.pPointer);
  1024. break;
  1025. }
  1026. case FIELD_GRAPH:
  1027. {
  1028. PService->FreeDataGraph((DataGraph*)pData.pPointer);
  1029. //delete ((DataGraph*)pData.pPointer);
  1030. break;
  1031. }
  1032. case FIELD_POSITION:
  1033. {
  1034. delete ((DataPosition*)pData.pPointer);
  1035. break;
  1036. }
  1037. case FIELD_STRING:
  1038. {
  1039. delete ((DataString*)pData.pPointer);
  1040. break;
  1041. }
  1042. case FIELD_UV:
  1043. {
  1044. delete ((DataUV*)pData.pPointer);
  1045. break;
  1046. }
  1047. case FIELD_COLOR:
  1048. {
  1049. delete ((DataColor*)pData.pPointer);
  1050. break;
  1051. }
  1052. default:
  1053. {
  1054. throw ("Particles: Try delete unknown field type !!!!");
  1055. }
  1056. } //switch
  1057. }
  1058. #ifndef _XBOX
  1059. void FieldList::WriteXML (TextFile* xmlFile, dword level)
  1060. {
  1061. xmlFile->Write((level+1), "<Fields>\n");
  1062. level++;
  1063. for (DWORD n = 0; n < GUID_MAX; n++)
  1064. {
  1065. if (Fields[n].Type == FIELD_UNKNOWN) continue;
  1066. switch (Fields[n].Type)
  1067. {
  1068. case FIELD_BOOL:
  1069. {
  1070. xmlFile->Write((level+1), "<Field val = \"FIELD_BOOL\">\n");
  1071. DataBool* pBoolField = (DataBool*)Fields[n].pPointer;
  1072. pBoolField->WriteXML (xmlFile, (level+1));
  1073. break;
  1074. }
  1075. case FIELD_FLOAT:
  1076. {
  1077. xmlFile->Write((level+1), "<Field val = \"FIELD_FLOAT\">\n");
  1078. DataFloat* pFloatField = (DataFloat*)Fields[n].pPointer;
  1079. pFloatField->WriteXML (xmlFile, (level+1));
  1080. break;
  1081. }
  1082. case FIELD_GRAPH:
  1083. {
  1084. xmlFile->Write((level+1), "<Field val = \"FIELD_GRAPH\">\n");
  1085. DataGraph* pGraphField = (DataGraph*)Fields[n].pPointer;
  1086. pGraphField->WriteXML (xmlFile, (level+1));
  1087. break;
  1088. }
  1089. case FIELD_POSITION:
  1090. {
  1091. xmlFile->Write((level+1), "<Field val = \"FIELD_POSITION\">\n");
  1092. DataPosition* pPositionField = (DataPosition*)Fields[n].pPointer;
  1093. pPositionField->WriteXML (xmlFile, (level+1));
  1094. break;
  1095. }
  1096. case FIELD_STRING:
  1097. {
  1098. xmlFile->Write((level+1), "<Field val = \"FIELD_STRING\">\n");
  1099. DataString* pStringField = (DataString*)Fields[n].pPointer;
  1100. pStringField->WriteXML (xmlFile, (level+1));
  1101. break;
  1102. }
  1103. case FIELD_UV:
  1104. {
  1105. xmlFile->Write((level+1), "<Field val = \"FIELD_UV\">\n");
  1106. DataUV* pUVField = (DataUV*)Fields[n].pPointer;
  1107. pUVField->WriteXML (xmlFile, (level+1));
  1108. break;
  1109. }
  1110. case FIELD_COLOR:
  1111. {
  1112. xmlFile->Write((level+1), "<Field val = \"FIELD_COLOR\">\n");
  1113. DataColor* pColorField = (DataColor*)Fields[n].pPointer;
  1114. pColorField->WriteXML (xmlFile, (level+1));
  1115. break;
  1116. }
  1117. default:
  1118. {
  1119. throw ("Particles: Unknown field type !!!!");
  1120. }
  1121. } //switch
  1122. xmlFile->Write((level+1), "</Field>\n");
  1123. } // loop
  1124. xmlFile->Write((level+0), "</Fields>\n");
  1125. }
  1126. #endif
  1127. void FieldList::Write (MemFile* File)
  1128. {
  1129. DWORD DataFieldsCount = 0;
  1130. for (dword n = 0; n < GUID_MAX; n++)
  1131. {
  1132. if (Fields[n].Type != FIELD_UNKNOWN)
  1133. {
  1134. DataFieldsCount++;
  1135. }
  1136. }
  1137. File->WriteType(DataFieldsCount);
  1138. for (DWORD n = 0; n < GUID_MAX; n++)
  1139. {
  1140. if (Fields[n].Type == FIELD_UNKNOWN) continue;
  1141. File->WriteType(Fields[n].Type);
  1142. switch (Fields[n].Type)
  1143. {
  1144. case FIELD_BOOL:
  1145. {
  1146. DataBool* pBoolField = (DataBool*)Fields[n].pPointer;
  1147. pBoolField->Write (File);
  1148. break;
  1149. }
  1150. case FIELD_FLOAT:
  1151. {
  1152. DataFloat* pFloatField = (DataFloat*)Fields[n].pPointer;
  1153. pFloatField->Write (File);
  1154. break;
  1155. }
  1156. case FIELD_GRAPH:
  1157. {
  1158. DataGraph* pGraphField = (DataGraph*)Fields[n].pPointer;
  1159. pGraphField->Write (File);
  1160. break;
  1161. }
  1162. case FIELD_POSITION:
  1163. {
  1164. DataPosition* pPositionField = (DataPosition*)Fields[n].pPointer;
  1165. pPositionField->Write (File);
  1166. break;
  1167. }
  1168. case FIELD_STRING:
  1169. {
  1170. DataString* pStringField = (DataString*)Fields[n].pPointer;
  1171. pStringField->Write (File);
  1172. break;
  1173. }
  1174. case FIELD_UV:
  1175. {
  1176. DataUV* pUVField = (DataUV*)Fields[n].pPointer;
  1177. pUVField->Write (File);
  1178. break;
  1179. }
  1180. case FIELD_COLOR:
  1181. {
  1182. DataColor* pColorField = (DataColor*)Fields[n].pPointer;
  1183. pColorField->Write (File);
  1184. break;
  1185. }
  1186. default:
  1187. {
  1188. throw ("Particles: Unknown field type !!!!");
  1189. }
  1190. } //switch
  1191. } // loop
  1192. }
  1193. void FieldList::UpdateCache ()
  1194. {
  1195. CachedGeomNames.DelAll();
  1196. const char* GeomNames = GetString(GUID_PARTICLE_GEOM_NAMES);
  1197. GeomNameParser Parser;
  1198. Parser.Tokenize(GeomNames);
  1199. for (dword i = 0; i < Parser.GetTokensCount(); i++)
  1200. {
  1201. CachedGeomNames.Add(Parser.GetTokenByIndex(i));
  1202. }
  1203. CachedForceFieldsID.DelAll();
  1204. if (pMaster)
  1205. {
  1206. const char* ForceFields = GetString(GUID_FORCEFIELDS_NAME);
  1207. //api->Trace("ff: '%s'", ForceFields);
  1208. Parser.Tokenize(ForceFields);
  1209. if (Parser.GetTokensCount() > 0)
  1210. {
  1211. for (dword z = 0; z < Parser.GetTokensCount(); z++)
  1212. {
  1213. const char* szForceFiledName = Parser.GetTokenByIndex(z);
  1214. if (szForceFiledName && szForceFiledName[0] == '#') continue;
  1215. //dword dwForceFieldGUID = pManager->GetForceFieldUniqueID(szForceFiledName);
  1216. //CachedForceFieldsID.Add(dwForceFieldGUID);
  1217. Assert(!"dword dwForceFieldGUID = pManager->GetForceFieldUniqueID(szForceFiledName);");
  1218. }
  1219. }
  1220. }
  1221. }
  1222. const char* FieldList::GetRandomModelNameFromCache()
  1223. {
  1224. if (CachedGeomNames.Size() == 0) return NULL;
  1225. return CachedGeomNames[(rand () % CachedGeomNames.Size())];
  1226. }
  1227. dword FieldList::GetForceFieldsCountFromCache ()
  1228. {
  1229. return CachedForceFieldsID.Size();
  1230. }
  1231. dword FieldList::GetForceFieldGUIDFromCache(dword dwIndex)
  1232. {
  1233. return CachedForceFieldsID[dwIndex];
  1234. }