assets.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/assets.cpp $*
  25. * *
  26. * $Author:: Jani_p $*
  27. * *
  28. * $Modtime:: 8/31/01 8:03p $*
  29. * *
  30. * $Revision:: 49 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "assets.h"
  36. #include "wwfile.h"
  37. #include "debug.h"
  38. #include "ffactory.h"
  39. /*
  40. **
  41. */
  42. INIClass * Get_INI( const char * filename )
  43. {
  44. INIClass * ini = NULL;
  45. FileClass * INIfile = _TheFileFactory->Get_File( filename );
  46. if ( INIfile ) {
  47. if ( INIfile->Is_Available() ) {
  48. ini = new INIClass( *INIfile );
  49. }
  50. _TheFileFactory->Return_File( INIfile );
  51. }
  52. return ini;
  53. }
  54. void Save_INI( INIClass * p_ini, const char * filename )
  55. {
  56. WWASSERT(p_ini != NULL);
  57. WWASSERT(filename != NULL);
  58. FileClass * p_INIfile = _TheWritingFileFactory->Get_File(filename);
  59. if (p_INIfile != NULL && p_INIfile->Is_Available()) {
  60. p_ini->Save(*p_INIfile);
  61. _TheWritingFileFactory->Return_File(p_INIfile);
  62. }
  63. }
  64. void Release_INI( INIClass * ini )
  65. {
  66. WWASSERT( ini );
  67. delete ini;
  68. }
  69. /*
  70. **
  71. */
  72. void Strip_Path_From_Filename( StringClass& new_name, const char * filename )
  73. {
  74. if ( ::strchr( filename, '\\' ) != 0 ) {
  75. new_name = ::strrchr( filename, '\\' ) + 1;
  76. }
  77. else new_name=filename;
  78. }
  79. /*
  80. ** Asset access
  81. */
  82. void Get_Render_Obj_Name_From_Filename( StringClass& new_name, const char * filename )
  83. {
  84. Strip_Path_From_Filename( new_name, filename );
  85. if ( new_name.Get_Length() > 4 ) {
  86. new_name.Erase( new_name.Get_Length() - 4, 4 );
  87. }
  88. }
  89. RenderObjClass * Create_Render_Obj_From_Filename( const char * filename )
  90. {
  91. StringClass render_obj_name(true);
  92. Strip_Path_From_Filename( render_obj_name, filename );
  93. render_obj_name.Erase( render_obj_name.Get_Length() - 4, 4 );
  94. RenderObjClass *model = WW3DAssetManager::Get_Instance()->Create_Render_Obj( render_obj_name );
  95. if ( model == NULL ) {
  96. Debug_Say(( "Failed to create \"%s\" from \"%s\"\n", (const char *)render_obj_name, filename ));
  97. }
  98. return model;
  99. }
  100. TextureClass * Get_Texture_From_Filename
  101. (
  102. const char * filename,
  103. TextureClass::MipCountType mip_level_count
  104. )
  105. {
  106. StringClass tex_name(true);
  107. Strip_Path_From_Filename( tex_name, filename );
  108. return WW3DAssetManager::Get_Instance()->Get_Texture( tex_name, mip_level_count );
  109. }
  110. /*
  111. ** Filenames
  112. */
  113. void Create_Animation_Name( StringClass& anim_name, const char * anim_filename, const char * model_name )
  114. {
  115. anim_name=anim_filename;
  116. if ( ::strrchr( anim_name, '\\' ) != 0 ) {
  117. StringClass temp(::strrchr( anim_name, '\\' ) + 1,true);
  118. anim_name = temp;
  119. anim_name.Erase( anim_name.Get_Length() - 4, 4 ); // Strip off ".w3d"
  120. }
  121. if ( ::strchr( anim_name, '.' ) == 0 ) { // Add model name
  122. StringClass temp(true);
  123. temp.Format( "%s.%s", model_name, anim_name );
  124. anim_name = temp;
  125. }
  126. }