modelIGC.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /*
  2. ** Copyright (C) 1996, 1997 Microsoft Corporation. All Rights Reserved.
  3. **
  4. ** File: modelIGC.h
  5. **
  6. ** Author:
  7. **
  8. ** Description:
  9. ** Header for the CmodelIGC class. This file was initially created by
  10. ** the ATL wizard.
  11. **
  12. ** History:
  13. */
  14. // modelIGC.h : Declaration of the CmodelIGC
  15. #ifndef __MODELIGC_H_
  16. #define __MODELIGC_H_
  17. template<class T> class TmodelIGC;
  18. class CmodelIGC
  19. {
  20. public:
  21. CmodelIGC(ImodelIGC* model);
  22. ~CmodelIGC(void);
  23. Time GetMyLastUpdate(void) const
  24. {
  25. return m_lastUpdate;
  26. }
  27. void SetMyLastUpdate(Time lastUpdate)
  28. {
  29. m_lastUpdate = lastUpdate;
  30. }
  31. ImissionIGC* GetMyMission(void) const
  32. {
  33. return m_pMission;
  34. }
  35. void SetMyMission(ImissionIGC* pMission)
  36. {
  37. assert (m_side == NULL);
  38. assert (m_cluster == NULL);
  39. m_pMission = pMission;
  40. }
  41. void MakeStatic(void)
  42. {
  43. assert ((m_attributes & c_mtStatic) == 0);
  44. assert ((m_attributes & c_mtHitable) == 0);
  45. assert ((m_attributes & c_mtCastRay) != 0);
  46. m_pHitTest->SetID(c_htidStaticObject);
  47. m_pHitTest->SetStaticF(true);
  48. assert (m_cluster);
  49. m_attributes &= ~c_mtCastRay;
  50. m_attributes |= c_mtStatic | c_mtHitable;
  51. m_cluster->MakeModelStatic(m_model);
  52. }
  53. void MakeUnhitable(void)
  54. {
  55. assert ((m_attributes & c_mtStatic) == 0);
  56. assert ((m_attributes & c_mtHitable) != 0);
  57. assert ((m_attributes & c_mtCastRay) != 0);
  58. assert (m_cluster);
  59. m_attributes &= ~(c_mtCastRay | c_mtHitable);
  60. m_cluster->MakeModelUnhitable(m_model);
  61. }
  62. private:
  63. void SetMyAttributes(ModelAttributes newVal);
  64. public:
  65. // IbaseIGC
  66. HRESULT Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize)
  67. {
  68. m_lastUpdate = now;
  69. m_pMission = pMission;
  70. return S_OK;
  71. }
  72. void Terminate(void);
  73. void Update(Time now);
  74. // ImodelIGC
  75. virtual void LoadCVH(const char* pszFileName,
  76. const char* pszIconName,
  77. ModelAttributes attributes,
  78. HitTestShape htsDefault = c_htsSphere);
  79. HRESULT LoadMine(const char* textureName, float strength, float radius, const char* iconName, ModelAttributes attributes);
  80. HRESULT LoadWarp(const char* textureName, const char* iconName, ModelAttributes attributes);
  81. HRESULT LoadEffect(const Color& color, ModelAttributes attributes);
  82. HRESULT Load(int options,
  83. const char* model,
  84. const char* texture,
  85. const char* icon,
  86. ModelAttributes attributes);
  87. bool GetVisibleF(void) const
  88. {
  89. return m_visibleF;
  90. }
  91. void SetVisibleF(bool visibleF);
  92. void SetRender(unsigned char render);
  93. bool SeenBySide(IsideIGC* side) const
  94. {
  95. if (!m_pThingSite)
  96. return false;
  97. return m_pThingSite->GetSideVisibility(side);
  98. }
  99. void UpdateSeenBySide(void)
  100. {
  101. m_pThingSite->UpdateSideVisibility(m_model, m_cluster);
  102. }
  103. void SetSideVisibility(IsideIGC* side,
  104. bool fVisible)
  105. {
  106. m_pThingSite->SetSideVisibility(side, fVisible);
  107. }
  108. ThingSite* GetThingSite(void) const
  109. {
  110. return m_pThingSite;
  111. }
  112. void FreeThingSite(void)
  113. {
  114. if (m_pHitTest)
  115. {
  116. if (m_cluster)
  117. {
  118. m_cluster->FreeThingSite(m_attributes, m_model, m_pHitTest);
  119. }
  120. m_pHitTest->Release();
  121. m_pHitTest = NULL;
  122. assert (m_pThingSite);
  123. m_pThingSite->Terminate();
  124. m_pThingSite = NULL;
  125. }
  126. else
  127. assert (!m_pThingSite);
  128. }
  129. const Vector& GetPosition(void) const
  130. {
  131. return m_pHitTest->GetPosition();
  132. }
  133. void SetPosition(const Vector& newVal);
  134. const Vector& GetVelocity(void) const
  135. {
  136. return m_pHitTest->GetVelocity();
  137. }
  138. void SetVelocity(const Vector& newVal)
  139. {
  140. assert (newVal * newVal >= 0.0f);
  141. m_pHitTest->SetVelocity(newVal);
  142. }
  143. const Orientation& GetOrientation(void) const
  144. {
  145. return m_pHitTest->GetOrientation();
  146. }
  147. void SetOrientation(const Orientation& newVal);
  148. const Rotation& GetRotation(void) const
  149. {
  150. return m_rotation;
  151. }
  152. void SetRotation(const Rotation& newVal)
  153. {
  154. m_rotation = newVal;
  155. }
  156. float GetRadius(void) const
  157. {
  158. return m_pHitTest->GetRadius();
  159. }
  160. void SetRadius(float newVal)
  161. {
  162. assert (newVal != 0.0f);
  163. m_pHitTest->SetRadius(newVal);
  164. m_pThingSite->SetRadius(newVal);
  165. }
  166. ModelAttributes GetAttributes(void) const
  167. {
  168. return m_attributes;
  169. }
  170. IsideIGC* GetSide(void) const
  171. {
  172. return m_side;
  173. }
  174. void SetSide(IsideIGC* newVal)
  175. {
  176. IsideIGC* psideOld = m_side;
  177. if (m_side)
  178. m_side->Release();
  179. m_side = newVal;
  180. if (m_side)
  181. m_side->AddRef();
  182. if (m_cluster)
  183. {
  184. //Warning ... this will probably cause a few assertion failures
  185. //till we get the sequence exactly right but we should never change
  186. //the side of an object that is in a cluster unless we are changing
  187. //from a legal side to a legal side.
  188. //assert (newVal); //Can't do this ... killing a station first sets its side to NULL
  189. assert (psideOld);
  190. //Reset the thing site's view of which cluster the model is in
  191. //(the cluster did not change but some of the internal state for
  192. //the thing site has to change to reflect the change in side)
  193. //This also updates the side visibility for the object.
  194. m_pThingSite->SetCluster(m_model, m_cluster);
  195. }
  196. }
  197. float GetMass(void) const
  198. {
  199. return m_mass;
  200. }
  201. void SetMass(float newVal)
  202. {
  203. m_mass = newVal;
  204. }
  205. IclusterIGC* GetCluster(void) const
  206. {
  207. return m_cluster;
  208. }
  209. void SetCluster(IclusterIGC* newVal);
  210. const char* GetName(void) const
  211. {
  212. return m_name;
  213. }
  214. void SetName(const char* newVal)
  215. {
  216. UTL::putName(m_name, newVal);
  217. }
  218. void SetSecondaryName(const char* newVal)
  219. {
  220. assert (strlen(newVal) < c_cbName-1);
  221. m_name[0] = '\0';
  222. strcpy(m_name+1, newVal);
  223. }
  224. void SetSignature(float newVal)
  225. {
  226. m_signature = newVal;
  227. }
  228. float GetSignature(void) const
  229. {
  230. return m_signature;
  231. }
  232. void ChangeSignature(float delta)
  233. {
  234. m_signature += delta;
  235. }
  236. void SetTexture(const char* pszTextureName)
  237. {
  238. m_pThingSite->SetTexture(pszTextureName);
  239. }
  240. HRESULT LoadDecal(const char* textureName,
  241. const char* iconName,
  242. const Color& color,
  243. bool bDirectional,
  244. float width,
  245. ModelAttributes attributes,
  246. HitTestShape htsDefault = c_htsPoint);
  247. void Move(float t)
  248. {
  249. m_pHitTest->Move(t);
  250. m_pThingSite->SetPosition(m_pHitTest->GetPosition());
  251. }
  252. void Move(void)
  253. {
  254. m_pHitTest->Move();
  255. m_pThingSite->SetPosition(m_pHitTest->GetPosition());
  256. }
  257. void SetBB(Time tStart, Time tStop, float dT)
  258. {
  259. m_pHitTest->SetBB(tStart, tStop, dT);
  260. }
  261. HitTest* GetHitTest(void) const
  262. {
  263. return m_pHitTest;
  264. }
  265. virtual IObject* GetIcon(void) const
  266. {
  267. return m_poIcon;
  268. }
  269. virtual void SetIcon(IObject* picon)
  270. {
  271. m_poIcon = picon;
  272. }
  273. virtual const DamageBucketList* GetDamageBuckets(void) const
  274. {
  275. return &m_damageBuckets;
  276. }
  277. virtual void AddDamageBucket(DamageBucket* pdb)
  278. {
  279. assert (m_pMission);
  280. m_damageBuckets.last(pdb);
  281. }
  282. virtual void DeleteDamageBucket(DamageBucket* pdb)
  283. {
  284. DamageBucketLink* pdbl = m_damageBuckets.find(pdb);
  285. assert (pdbl);
  286. delete pdbl;
  287. }
  288. private:
  289. ImissionIGC* m_pMission;
  290. Time m_lastUpdate;
  291. TRef<ThingSite> m_pThingSite;
  292. TRef<IObject> m_poIcon;
  293. IsideIGC* m_side;
  294. DamageBucketList m_damageBuckets;
  295. ImodelIGC* m_model; //pointer for anything that needs a pointer to the "model" & not the class implementation
  296. Rotation m_rotation;
  297. IclusterIGC* m_cluster;
  298. float m_mass;
  299. float m_signature;
  300. HitTest* m_pHitTest;
  301. char m_name[c_cbName];
  302. ModelAttributes m_attributes;
  303. bool m_visibleF;
  304. bool m_selectedF;
  305. bool m_decalF;
  306. unsigned char m_render;
  307. };
  308. template<class T> class TmodelIGC : public T
  309. {
  310. public:
  311. TmodelIGC(void)
  312. :
  313. m_model(this)
  314. {
  315. }
  316. //Note ... these methods are not part of the ImodelIGC interface (& not virtual either)
  317. Time GetMyLastUpdate(void) const
  318. {
  319. return m_model.GetMyLastUpdate();
  320. }
  321. void SetMyLastUpdate(Time lastUpdate)
  322. {
  323. m_model.SetMyLastUpdate(lastUpdate);
  324. }
  325. ImissionIGC* GetMyMission(void) const
  326. {
  327. return m_model.GetMyMission();
  328. }
  329. void SetMyMission(ImissionIGC* pMission)
  330. {
  331. m_model.SetMyMission(pMission);
  332. }
  333. void MakeStatic(void)
  334. {
  335. m_model.MakeStatic();
  336. }
  337. void MakeUnhitable(void)
  338. {
  339. m_model.MakeUnhitable();
  340. }
  341. // IbaseIGC
  342. virtual HRESULT Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize)
  343. {
  344. return m_model.Initialize(pMission, now, data, dataSize);
  345. }
  346. virtual void Terminate(void)
  347. {
  348. m_model.Terminate();
  349. }
  350. virtual void Update(Time now)
  351. {
  352. m_model.Update(now);
  353. }
  354. virtual ImissionIGC* GetMission(void) const
  355. {
  356. return m_model.GetMyMission();
  357. }
  358. // ImodelIGC
  359. virtual Time GetLastUpdate(void) const
  360. {
  361. return m_model.GetMyLastUpdate();
  362. }
  363. virtual void SetLastUpdate(Time now)
  364. {
  365. m_model.SetMyLastUpdate(now);
  366. }
  367. virtual void SetMission(ImissionIGC* pMission)
  368. {
  369. m_model.SetMyMission(pMission);
  370. }
  371. virtual void LoadCVH(const char* pszFileName,
  372. const char* pszIconName,
  373. ModelAttributes attributes,
  374. HitTestShape htsDefault = c_htsSphere)
  375. {
  376. m_model.LoadCVH(pszFileName, pszIconName, attributes, htsDefault);
  377. }
  378. virtual HRESULT LoadEffect(const Color& color, ModelAttributes attributes)
  379. {
  380. return m_model.LoadEffect(color, attributes);
  381. }
  382. virtual HRESULT LoadMine(const char* textureName, float strength, float radius, const char* icon, ModelAttributes attributes)
  383. {
  384. return m_model.LoadMine(textureName, strength, radius, icon, attributes);
  385. }
  386. virtual HRESULT LoadWarp(const char* textureName, const char* icon, ModelAttributes attributes)
  387. {
  388. return m_model.LoadWarp(textureName, icon, attributes);
  389. }
  390. virtual HRESULT Load(int options,
  391. const char* model,
  392. const char* texture,
  393. const char* icon,
  394. ModelAttributes attributes)
  395. {
  396. return m_model.Load(options, model, texture, icon, attributes);
  397. }
  398. virtual bool GetVisibleF(void) const
  399. {
  400. return m_model.GetVisibleF();
  401. }
  402. virtual void SetVisibleF(bool visibleF)
  403. {
  404. m_model.SetVisibleF(visibleF);
  405. }
  406. virtual void SetRender(unsigned char render)
  407. {
  408. m_model.SetRender(render);
  409. }
  410. virtual bool SeenBySide(IsideIGC* side) const
  411. {
  412. return m_model.SeenBySide(side);
  413. }
  414. virtual void UpdateSeenBySide(void)
  415. {
  416. m_model.UpdateSeenBySide();
  417. }
  418. virtual void SetSideVisibility(IsideIGC* side, bool fVisible)
  419. {
  420. m_model.SetSideVisibility(side, fVisible);
  421. }
  422. virtual ThingSite* GetThingSite(void) const
  423. {
  424. return m_model.GetThingSite();
  425. }
  426. virtual void FreeThingSite(void)
  427. {
  428. m_model.FreeThingSite();
  429. }
  430. virtual const Vector& GetPosition(void) const
  431. {
  432. return m_model.GetPosition();
  433. }
  434. virtual void SetPosition(const Vector& newVal)
  435. {
  436. m_model.SetPosition(newVal);
  437. }
  438. virtual const Vector& GetVelocity(void) const
  439. {
  440. return m_model.GetVelocity();
  441. }
  442. virtual void SetVelocity(const Vector& newVal)
  443. {
  444. m_model.SetVelocity(newVal);
  445. }
  446. virtual const Orientation& GetOrientation(void) const
  447. {
  448. return m_model.GetOrientation();
  449. }
  450. virtual void SetOrientation(const Orientation& newVal)
  451. {
  452. m_model.SetOrientation(newVal);
  453. }
  454. virtual const Rotation& GetRotation(void) const
  455. {
  456. return m_model.GetRotation();
  457. }
  458. virtual void SetRotation(const Rotation& newVal)
  459. {
  460. m_model.SetRotation(newVal);
  461. }
  462. virtual float GetRadius(void) const
  463. {
  464. return m_model.GetRadius();
  465. }
  466. virtual void SetRadius(float newVal)
  467. {
  468. m_model.SetRadius(newVal);
  469. }
  470. virtual ModelAttributes GetAttributes(void) const
  471. {
  472. return m_model.GetAttributes();
  473. }
  474. virtual IsideIGC* GetSide(void) const
  475. {
  476. return m_model.GetSide();
  477. }
  478. virtual void SetSide(IsideIGC* newVal)
  479. {
  480. m_model.SetSide(newVal);
  481. }
  482. virtual float GetMass(void) const
  483. {
  484. return m_model.GetMass();
  485. }
  486. virtual void SetMass(float newVal)
  487. {
  488. m_model.SetMass(newVal);
  489. }
  490. virtual IclusterIGC* GetCluster(void) const
  491. {
  492. return m_model.GetCluster();
  493. }
  494. virtual void SetCluster(IclusterIGC* newVal)
  495. {
  496. m_model.SetCluster(newVal);
  497. }
  498. virtual char const* GetName(void) const
  499. {
  500. return m_model.GetName();
  501. }
  502. virtual void SetName(const char* newVal)
  503. {
  504. m_model.SetName(newVal);
  505. }
  506. void SetSecondaryName(const char* newVal)
  507. {
  508. m_model.SetSecondaryName(newVal);
  509. }
  510. virtual float GetSignature(void) const
  511. {
  512. return m_model.GetSignature();
  513. }
  514. virtual void SetSignature(float newVal)
  515. {
  516. m_model.SetSignature(newVal);
  517. }
  518. virtual void ChangeSignature(float delta)
  519. {
  520. m_model.ChangeSignature(delta);
  521. }
  522. virtual void SetTexture(const char* pszTextureName)
  523. {
  524. m_model.SetTexture(pszTextureName);
  525. }
  526. virtual HRESULT LoadDecal(const char* textureName,
  527. const char* iconName,
  528. const Color& color,
  529. bool bDirectional,
  530. float width,
  531. ModelAttributes attributes,
  532. HitTestShape htsDefault = c_htsPoint)
  533. {
  534. return m_model.LoadDecal(textureName, iconName, color, bDirectional, width, attributes, htsDefault);
  535. }
  536. virtual void Move(float t)
  537. {
  538. m_model.Move(t);
  539. }
  540. virtual void Move(void)
  541. {
  542. m_model.Move();
  543. }
  544. virtual void SetBB(Time tStart, Time tStop, float dt)
  545. {
  546. m_model.SetBB(tStart, tStop, dt);
  547. }
  548. virtual HitTest* GetHitTest(void) const
  549. {
  550. return m_model.GetHitTest();
  551. }
  552. virtual void HandleCollision(Time timeCollision,
  553. float tCollision,
  554. const CollisionEntry& entry,
  555. ImodelIGC* pModel)
  556. {
  557. //Should never be called
  558. assert (false);
  559. }
  560. virtual IObject* GetIcon(void) const
  561. {
  562. return m_model.GetIcon();
  563. }
  564. virtual void SetIcon(IObject* picon)
  565. {
  566. m_model.SetIcon(picon);
  567. }
  568. virtual const DamageBucketList* GetDamageBuckets(void) const
  569. {
  570. return m_model.GetDamageBuckets();
  571. }
  572. virtual void AddDamageBucket(DamageBucket* pdb)
  573. {
  574. m_model.AddDamageBucket(pdb);
  575. }
  576. virtual void DeleteDamageBucket(DamageBucket* pdb)
  577. {
  578. m_model.DeleteDamageBucket(pdb);
  579. }
  580. private:
  581. CmodelIGC m_model;
  582. };
  583. #endif //__MODELIGC_H_