Anim3D.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. // Anim3D.CPP
  19. // Project: Postal
  20. //
  21. // History:
  22. // 05/23/97 JMI Started. Moved here from thing.h.
  23. // Also, added events.
  24. //
  25. // 08/01/97 BRH Took out loading/releasing .hot channels since
  26. // we aren't using them.
  27. //
  28. // 08/07/97 JMI Added m_ptransWeapon rigid body transforms channel for
  29. // weapons.
  30. // Also, added SetLooping().
  31. // Also, removed all (including commented out) references to
  32. // hots and floors.
  33. //
  34. // 08/11/97 JMI Now has TRACEs to complain when an animation fails to
  35. // load.
  36. // Also, on the first component to fail, no more are loaded.
  37. // Also, if any fail to load, all that were loaded are
  38. // released.
  39. //
  40. // 08/12/97 BRH Added yet another overloaded version of Get which
  41. // takes a number of a texture file to be loaded.
  42. //
  43. // 12/17/97 JMI Now if the sTextureScheme values is less than zero, no
  44. // number is used (i.e., the default texture scheme is used).
  45. //
  46. // 10/07/99 JMI Added conditional compile options for some error messages.
  47. //
  48. //////////////////////////////////////////////////////////////////////////////
  49. //
  50. // 3D animation class that is a collection of channels that make up a 3D
  51. // animation.
  52. //
  53. //////////////////////////////////////////////////////////////////////////////
  54. #define ANIM3D_CPP
  55. #include "RSPiX.h"
  56. #include "Anim3D.h"
  57. #include "game.h"
  58. ////////////////////////////////////////////////////////////////////////////////
  59. // Macros/types/etc.
  60. ////////////////////////////////////////////////////////////////////////////////
  61. ////////////////////////////////////////////////////////////////////////////////
  62. // Variables/data
  63. ////////////////////////////////////////////////////////////////////////////////
  64. ////////////////////////////////////////////////////////////////////////////////
  65. // Functions.
  66. ////////////////////////////////////////////////////////////////////////////////
  67. ////////////////////////////////////////////////////////////////////////////////
  68. // Default constructor.
  69. ////////////////////////////////////////////////////////////////////////////////
  70. CAnim3D::CAnim3D()
  71. {
  72. m_psops = NULL;
  73. m_pmeshes = NULL;
  74. m_ptextures = NULL;
  75. m_pbounds = NULL;
  76. m_ptransRigid = NULL;
  77. m_pevent = NULL;
  78. m_ptransWeapon = NULL;
  79. }
  80. ////////////////////////////////////////////////////////////////////////////////
  81. // Get the various components of this animation from the resource names
  82. // specified in the provided array of pointers to strings.
  83. // (virtual)
  84. ////////////////////////////////////////////////////////////////////////////////
  85. short CAnim3D::Get( // Returns 0 on success.
  86. char** ppszFileNames) // Pointer to array of pointers to filenames.
  87. // These filenames should be in the order
  88. // the members are listed in this class's
  89. // definition.
  90. {
  91. short sRes;
  92. short sComplainIndex; // If sRes is non-zero, this is the index of the
  93. // resname that could not load.
  94. // NOTE: If you add any new channel loads here, please make sure
  95. // you maintain the order described above.
  96. sComplainIndex = 0;
  97. sRes = rspGetResource(&g_resmgrGame, ppszFileNames[sComplainIndex], &m_psops);
  98. if (sRes == 0)
  99. {
  100. sComplainIndex = 1;
  101. sRes = rspGetResource(&g_resmgrGame, ppszFileNames[sComplainIndex], &m_pmeshes);
  102. if (sRes == 0)
  103. {
  104. sComplainIndex = 2;
  105. sRes = rspGetResource(&g_resmgrGame, ppszFileNames[sComplainIndex], &m_ptextures);
  106. if (sRes == 0)
  107. {
  108. sComplainIndex = 4;
  109. sRes = rspGetResource(&g_resmgrGame, ppszFileNames[sComplainIndex], &m_pbounds);
  110. if (sRes == 0)
  111. {
  112. sComplainIndex = 6;
  113. if (ppszFileNames[sComplainIndex] != NULL)
  114. {
  115. sRes = rspGetResource(&g_resmgrGame, ppszFileNames[sComplainIndex], &m_ptransRigid);
  116. }
  117. }
  118. }
  119. }
  120. }
  121. // No current support for events since that might break existing
  122. // arrays of size 6 elements.
  123. // No current support for weapon transforms either.
  124. // If an error occurred . . .
  125. if (sRes != 0)
  126. {
  127. #if defined(VERBOSE)
  128. // Complain.
  129. TRACE("Get(): Unable to load \"%s\".\n", ppszFileNames[sComplainIndex] );
  130. #endif
  131. // Clean.
  132. Release();
  133. }
  134. return sRes;
  135. }
  136. ////////////////////////////////////////////////////////////////////////////////
  137. // Get the various components of this animation from the resource names
  138. // specified in the provided array of pointers to strings.
  139. // (virtual)
  140. ////////////////////////////////////////////////////////////////////////////////
  141. short CAnim3D::Get( // Returns 0 on success.
  142. char** ppszFileNames, // Pointer to array of pointers to filenames.
  143. // These filenames should be in the order
  144. // the members are listed in this class's
  145. // definition.
  146. short sLoopFlags) // Looping flags to apply to all channels in this anim
  147. {
  148. short sRes = Get(ppszFileNames);
  149. // If successful . . .
  150. if (sRes == 0)
  151. {
  152. SetLooping(sLoopFlags);
  153. }
  154. return sRes;
  155. }
  156. ////////////////////////////////////////////////////////////////////////////////
  157. // Get the various components of this animation from the resource names
  158. // specified by base name, optionally, with a rigid name.
  159. // (virtual)
  160. ////////////////////////////////////////////////////////////////////////////////
  161. short CAnim3D::Get( // Returns 0 on success.
  162. char* pszBaseFileName, // In: Base string for resource filenames.
  163. char* pszRigidName, // In: String to add for rigid transform channel,
  164. // "", or NULL for none.
  165. char* pszEventName, // In: String to add for event states channel,
  166. // "", or NULL for none.
  167. char* pszWeaponTransName, // In: String to add for weapon transforms channel,
  168. // "", or NULL for none.
  169. short sLoopFlags) // In: Looping flags to apply to all channels
  170. // in this anim.
  171. {
  172. short sRes;
  173. char szResName[RSP_MAX_PATH];
  174. sprintf(szResName, "%s.sop", pszBaseFileName);
  175. sRes = rspGetResource(&g_resmgrGame, szResName, &m_psops);
  176. if (sRes == 0)
  177. {
  178. sprintf(szResName, "%s.mesh", pszBaseFileName);
  179. sRes = rspGetResource(&g_resmgrGame, szResName, &m_pmeshes);
  180. if (sRes == 0)
  181. {
  182. sprintf(szResName, "%s.tex", pszBaseFileName);
  183. sRes = rspGetResource(&g_resmgrGame, szResName, &m_ptextures);
  184. if (sRes == 0)
  185. {
  186. sprintf(szResName, "%s.bounds", pszBaseFileName);
  187. sRes = rspGetResource(&g_resmgrGame, szResName, &m_pbounds);
  188. if (sRes == 0)
  189. {
  190. if (pszRigidName != NULL)
  191. {
  192. if (*pszRigidName != '\0')
  193. {
  194. sprintf(szResName, "%s_%s.trans", pszBaseFileName, pszRigidName);
  195. sRes = rspGetResource(&g_resmgrGame, szResName, &m_ptransRigid);
  196. }
  197. }
  198. if (sRes == 0)
  199. {
  200. if (pszEventName != NULL)
  201. {
  202. if (*pszEventName != '\0')
  203. {
  204. sprintf(szResName, "%s_%s.event", pszBaseFileName, pszEventName);
  205. sRes = rspGetResource(&g_resmgrGame, szResName, &m_pevent);
  206. }
  207. }
  208. if (sRes == 0)
  209. {
  210. if (pszWeaponTransName != NULL)
  211. {
  212. if (*pszWeaponTransName != '\0')
  213. {
  214. sprintf(szResName, "%s_%s.trans", pszBaseFileName, pszWeaponTransName);
  215. sRes = rspGetResource(&g_resmgrGame, szResName, &m_ptransWeapon);
  216. }
  217. }
  218. }
  219. }
  220. }
  221. }
  222. }
  223. }
  224. // If successful . . .
  225. if (sRes == 0)
  226. {
  227. SetLooping(sLoopFlags);
  228. }
  229. else
  230. {
  231. #if defined(VERBOSE)
  232. TRACE("Get(): Unable to load \"%s\".\n", szResName);
  233. #endif
  234. // Clean.
  235. Release();
  236. }
  237. return sRes;
  238. }
  239. ////////////////////////////////////////////////////////////////////////////////
  240. // Get the various components of this animation from the resource names
  241. // specified by base name, optionally, with a rigid name.
  242. // (virtual)
  243. ////////////////////////////////////////////////////////////////////////////////
  244. short CAnim3D::Get( // Returns 0 on success.
  245. char* pszBaseFileName, // In: Base string for resource filenames.
  246. char* pszVerb, // In: Action name to be appended to the base
  247. char* pszRigidName, // In: String to add for rigid transform channel,
  248. // "", or NULL for none.
  249. char* pszEventName, // In: String to add for event states channel,
  250. // "", or NULL for none.
  251. char* pszWeaponTransName, // In: String to add for weapon transforms channel,
  252. // "", or NULL for none.
  253. short sLoopFlags) // In: Looping flags to apply to all channels
  254. // in this anim.
  255. {
  256. char szVerbedBaseName[RSP_MAX_PATH];
  257. sprintf(szVerbedBaseName, "%s_%s", pszBaseFileName, pszVerb);
  258. return Get(szVerbedBaseName, pszRigidName, pszEventName, pszWeaponTransName, sLoopFlags);
  259. }
  260. ////////////////////////////////////////////////////////////////////////////////
  261. // Get the various components of the animation using the given resource names,
  262. // but load only 1 .tex file based on the color scheme number passed in.
  263. ////////////////////////////////////////////////////////////////////////////////
  264. short CAnim3D::Get( // Returns 0 on success.
  265. char* pszBaseFileName, // In: Base string for resource filenames.
  266. short sTextureScheme, // In: Number to append after name for texture file
  267. char* pszVerb, // In: Action name to be appended to the base
  268. char* pszRigidName, // In: String to add for rigid transform channel,
  269. // "", or NULL for none.
  270. char* pszEventName, // In: String to add for event states channel,
  271. // "", or NULL for none.
  272. char* pszWeaponTransName, // In: String to add for weapon transforms channel,
  273. // "", or NULL for none.
  274. short sLoopFlags) // In: Looping flags to apply to all channels
  275. // in this anim.
  276. {
  277. char szVerbedBaseName[RSP_MAX_PATH];
  278. sprintf(szVerbedBaseName, "%s_%s", pszBaseFileName, pszVerb);
  279. short sRes;
  280. char szResName[RSP_MAX_PATH];
  281. sprintf(szResName, "%s.sop", szVerbedBaseName);
  282. sRes = rspGetResource(&g_resmgrGame, szResName, &m_psops);
  283. if (sRes == 0)
  284. {
  285. sprintf(szResName, "%s.mesh", szVerbedBaseName);
  286. sRes = rspGetResource(&g_resmgrGame, szResName, &m_pmeshes);
  287. if (sRes == 0)
  288. {
  289. // If there's an associated texture scheme . . .
  290. if (sTextureScheme >= 0)
  291. {
  292. sprintf(szResName, "%s%d.tex", pszBaseFileName, sTextureScheme);
  293. }
  294. else
  295. {
  296. sprintf(szResName, "%s.tex", szVerbedBaseName);
  297. }
  298. sRes = rspGetResource(&g_resmgrGame, szResName, &m_ptextures);
  299. if (sRes == 0)
  300. {
  301. sprintf(szResName, "%s.bounds", szVerbedBaseName);
  302. sRes = rspGetResource(&g_resmgrGame, szResName, &m_pbounds);
  303. if (sRes == 0)
  304. {
  305. if (pszRigidName != NULL)
  306. {
  307. if (*pszRigidName != '\0')
  308. {
  309. sprintf(szResName, "%s_%s.trans", szVerbedBaseName, pszRigidName);
  310. sRes = rspGetResource(&g_resmgrGame, szResName, &m_ptransRigid);
  311. }
  312. }
  313. if (sRes == 0)
  314. {
  315. if (pszEventName != NULL)
  316. {
  317. if (*pszEventName != '\0')
  318. {
  319. sprintf(szResName, "%s_%s.event", szVerbedBaseName, pszEventName);
  320. sRes = rspGetResource(&g_resmgrGame, szResName, &m_pevent);
  321. }
  322. }
  323. if (sRes == 0)
  324. {
  325. if (pszWeaponTransName != NULL)
  326. {
  327. if (*pszWeaponTransName != '\0')
  328. {
  329. sprintf(szResName, "%s_%s.trans", szVerbedBaseName, pszWeaponTransName);
  330. sRes = rspGetResource(&g_resmgrGame, szResName, &m_ptransWeapon);
  331. }
  332. }
  333. }
  334. }
  335. }
  336. }
  337. }
  338. }
  339. // If successful . . .
  340. if (sRes == 0)
  341. {
  342. SetLooping(sLoopFlags);
  343. }
  344. else
  345. {
  346. #if defined(VERBOSE)
  347. TRACE("Get(): Unable to load \"%s\".\n", szResName);
  348. #endif
  349. // Clean.
  350. Release();
  351. }
  352. return sRes;
  353. }
  354. ////////////////////////////////////////////////////////////////////////////////
  355. // Release all resources.
  356. // (virtual)
  357. ////////////////////////////////////////////////////////////////////////////////
  358. void CAnim3D::Release(void) // Returns nothing.
  359. {
  360. if (m_psops != NULL)
  361. rspReleaseResource(&g_resmgrGame, &m_psops);
  362. if (m_pmeshes != NULL)
  363. rspReleaseResource(&g_resmgrGame, &m_pmeshes);
  364. if (m_ptextures != NULL)
  365. rspReleaseResource(&g_resmgrGame, &m_ptextures);
  366. if (m_pbounds != NULL)
  367. rspReleaseResource(&g_resmgrGame, &m_pbounds);
  368. if (m_ptransRigid != NULL)
  369. rspReleaseResource(&g_resmgrGame, &m_ptransRigid);
  370. if (m_pevent != NULL)
  371. rspReleaseResource(&g_resmgrGame, &m_pevent);
  372. if (m_ptransWeapon)
  373. rspReleaseResource(&g_resmgrGame, &m_ptransWeapon);
  374. }
  375. ////////////////////////////////////////////////////////////////////////////////
  376. // Set looping flags for this channel.
  377. // (virtual)
  378. ////////////////////////////////////////////////////////////////////////////////
  379. void CAnim3D::SetLooping( // Returns nothing.
  380. short sLoopFlags) // In: Looping flags to apply to all channels
  381. // in this anim.
  382. {
  383. m_psops->SetLooping(sLoopFlags);
  384. m_pmeshes->SetLooping(sLoopFlags);
  385. m_ptextures->SetLooping(sLoopFlags);
  386. m_pbounds->SetLooping(sLoopFlags);
  387. if (m_ptransRigid != NULL)
  388. m_ptransRigid->SetLooping(sLoopFlags);
  389. if (m_pevent != NULL)
  390. m_pevent->SetLooping(sLoopFlags);
  391. if (m_ptransWeapon)
  392. m_ptransWeapon->SetLooping(sLoopFlags);
  393. }
  394. ////////////////////////////////////////////////////////////////////////////////
  395. // EOF
  396. ////////////////////////////////////////////////////////////////////////////////