lightsolvesavesystem.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : LevelEdit *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/LevelEdit/lightsolvesavesystem.cpp $*
  25. * *
  26. * Original Author:: Greg Hjelstrom *
  27. * *
  28. * $Author:: Greg_h $*
  29. * *
  30. * $Modtime:: 3/04/02 11:41a $*
  31. * *
  32. * $Revision:: 2 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #include "stdafx.h"
  38. #include "lightsolvesavesystem.h"
  39. #include "sceneeditor.h"
  40. #include "utils.h"
  41. #include "chunkio.h"
  42. #include "saveload.h"
  43. #include "editorchunkids.h"
  44. #include "staticphys.h"
  45. #include "pscene.h"
  46. #include "dx8renderer.h"
  47. /*
  48. ** Instantiate the save system
  49. */
  50. LightSolveSaveSystemClass _TheLightSolveSaveSystem;
  51. /************************************************************************************************
  52. **
  53. ** LightSolveSaveSystemClass Implementation
  54. **
  55. ************************************************************************************************/
  56. uint32 LightSolveSaveSystemClass::Chunk_ID(void) const
  57. {
  58. return CHUNKID_EDITOR_LIGHT_SOLVE_SAVELOAD;
  59. }
  60. bool LightSolveSaveSystemClass::Contains_Data(void) const
  61. {
  62. // TODO: could check if we have anything to save...
  63. return true;
  64. }
  65. bool LightSolveSaveSystemClass::Save(ChunkSaveClass &csave)
  66. {
  67. SceneEditorClass * scene = ::Get_Scene_Editor();
  68. WWASSERT(scene != NULL);
  69. RefPhysListIterator it = scene->Get_Static_Object_Iterator();
  70. while (!it.Is_Done()) {
  71. StaticPhysClass * pobj = it.Peek_Obj()->As_StaticPhysClass();
  72. if ( (pobj != NULL) &&
  73. (pobj->Peek_Model() != NULL) &&
  74. (pobj->Peek_Model()->Has_User_Lighting) )
  75. {
  76. csave.Begin_Chunk(LSS_CHUNKID_OBJECT_LIGHT_SOLVE);
  77. Save_Lighting_For_Object(csave,pobj);
  78. csave.End_Chunk();
  79. }
  80. it.Next();
  81. }
  82. return true;
  83. }
  84. bool LightSolveSaveSystemClass::Save_Lighting_For_Object(ChunkSaveClass & csave,StaticPhysClass * pobj)
  85. {
  86. RenderObjClass * model = pobj->Peek_Model();
  87. uint32 id = pobj->Get_ID();
  88. uint32 classid = (uint32)model->Class_ID();
  89. uint32 subobjcount = (uint32)model->Get_Num_Sub_Objects();
  90. csave.Begin_Chunk(LSS_CHUNKID_OBJECT_VARIABLES);
  91. WRITE_MICRO_CHUNK(csave,LSS_VARIABLE_OBJECT_ID,id);
  92. WRITE_MICRO_CHUNK(csave,LSS_VARIABLE_OBJECT_CLASSID,classid);
  93. WRITE_MICRO_CHUNK(csave,LSS_VARIABLE_OBJECT_SUBOBJCOUNT,subobjcount);
  94. csave.End_Chunk();
  95. csave.Begin_Chunk(LSS_CHUNKID_OBJECT_LIGHTING);
  96. model->Save_User_Lighting(csave);
  97. csave.End_Chunk();
  98. return true;
  99. }
  100. bool LightSolveSaveSystemClass::Load(ChunkLoadClass &cload)
  101. {
  102. while (cload.Open_Chunk()) {
  103. switch(cload.Cur_Chunk_ID())
  104. {
  105. case LSS_CHUNKID_OBJECT_LIGHT_SOLVE:
  106. Load_Lighting_For_Object(cload);
  107. break;
  108. default:
  109. WWDEBUG_SAY(("Unhandled Chunk: 0x%X File: %s Line: %d\r\n",cload.Cur_Chunk_ID(),__FILE__,__LINE__));
  110. break;
  111. }
  112. cload.Close_Chunk();
  113. }
  114. return true;
  115. }
  116. bool LightSolveSaveSystemClass::Load_Lighting_For_Object(ChunkLoadClass & cload)
  117. {
  118. uint32 id = 0;
  119. uint32 classid = 0;
  120. uint32 subobjcount = 0;
  121. /*
  122. ** Read in the variables, return if we do not detect the variables chunk first
  123. */
  124. cload.Open_Chunk();
  125. if (cload.Cur_Chunk_ID() != LSS_CHUNKID_OBJECT_VARIABLES) {
  126. cload.Close_Chunk();
  127. return false;
  128. }
  129. if (cload.Cur_Chunk_ID() == LSS_CHUNKID_OBJECT_VARIABLES) {
  130. while (cload.Open_Micro_Chunk()) {
  131. switch(cload.Cur_Micro_Chunk_ID()) {
  132. READ_MICRO_CHUNK(cload,LSS_VARIABLE_OBJECT_ID,id);
  133. READ_MICRO_CHUNK(cload,LSS_VARIABLE_OBJECT_CLASSID,classid);
  134. READ_MICRO_CHUNK(cload,LSS_VARIABLE_OBJECT_SUBOBJCOUNT,subobjcount);
  135. }
  136. cload.Close_Micro_Chunk();
  137. }
  138. }
  139. cload.Close_Chunk();
  140. /*
  141. ** Look up the object
  142. */
  143. StaticPhysClass * obj = PhysicsSceneClass::Get_Instance()->Get_Static_Object_By_ID(id);
  144. if (obj != NULL) {
  145. RenderObjClass * model = obj->Peek_Model();
  146. if ( (model != NULL) &&
  147. (obj->Get_ID() == id) &&
  148. (model->Class_ID() == (int)classid) &&
  149. (model->Get_Num_Sub_Objects() == (int)subobjcount) )
  150. {
  151. /*
  152. ** If we find the object, load its lighting data
  153. */
  154. if ((cload.Open_Chunk() == true) && (cload.Cur_Chunk_ID() == LSS_CHUNKID_OBJECT_LIGHTING)) {
  155. model->Load_User_Lighting(cload);
  156. cload.Close_Chunk();
  157. }
  158. }
  159. }
  160. return true;
  161. }
  162. void LightSolveSaveSystemClass::On_Post_Load(void)
  163. {
  164. /*
  165. ** The dx8 renderer needs to be reset so that the light solves get installed
  166. */
  167. TheDX8MeshRenderer.Invalidate();
  168. }