lightphys.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 : WWPhys *
  23. * *
  24. * $Archive:: /Commando/Code/wwphys/lightphys.cpp $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 3/01/02 3:32p $*
  29. * *
  30. * $Revision:: 22 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "lightphys.h"
  36. #include "w3d_file.h"
  37. #include "chunkio.h"
  38. #include "light.h"
  39. #include "matrix3.h"
  40. #include "persistfactory.h"
  41. #include "wwphysids.h"
  42. #include "lightexclude.h"
  43. #include "wwhack.h"
  44. #include "vistable.h"
  45. DECLARE_FORCE_LINK(lightphys);
  46. /*
  47. ** Declare a PersistFactory for LightPhysClasses
  48. */
  49. SimplePersistFactoryClass<LightPhysClass,PHYSICS_CHUNKID_LIGHTPHYS> _LightPhysFactory;
  50. /*
  51. ** Chunk ID's used by LightPhysClass
  52. */
  53. enum
  54. {
  55. LIGHTPHYS_CHUNK_DECOPHYS = 0x00770010,
  56. LIGHTPHYS_CHUNK_VARIABLES,
  57. LIGHTPHYS_VARIABLE_VISSECTORID = 0x00,
  58. LIGHTPHYS_VARIABLE_GROUPID,
  59. };
  60. LightPhysClass::LightPhysClass(bool auto_allocate_light) :
  61. VisSectorID(0xFFFFFFFF),
  62. GroupID(0)
  63. {
  64. if (auto_allocate_light) {
  65. LightClass * new_light = NEW_REF(LightClass,());
  66. Set_Model(new_light);
  67. new_light->Release_Ref();
  68. }
  69. }
  70. void LightPhysClass::Set_Model(RenderObjClass * model)
  71. {
  72. DecorationPhysClass::Set_Model(model);
  73. }
  74. int LightPhysClass::Is_Vis_Object_Visible(int vis_object_id)
  75. {
  76. if (VisSectorID == 0xFFFFFFFF) {
  77. return 1;
  78. }
  79. VisTableClass * pvs = PhysicsSceneClass::Get_Instance()->Get_Vis_Table(VisSectorID);
  80. if (pvs != NULL) {
  81. int vis_bit = pvs->Get_Bit(vis_object_id);
  82. REF_PTR_RELEASE(pvs);
  83. return vis_bit;
  84. }
  85. return 1;
  86. }
  87. const PersistFactoryClass & LightPhysClass::Get_Factory (void) const
  88. {
  89. return _LightPhysFactory;
  90. }
  91. bool LightPhysClass::Save (ChunkSaveClass &csave)
  92. {
  93. csave.Begin_Chunk(LIGHTPHYS_CHUNK_DECOPHYS);
  94. DecorationPhysClass::Save(csave);
  95. csave.End_Chunk();
  96. csave.Begin_Chunk(LIGHTPHYS_CHUNK_VARIABLES);
  97. WRITE_MICRO_CHUNK(csave,LIGHTPHYS_VARIABLE_VISSECTORID,VisSectorID);
  98. WRITE_MICRO_CHUNK(csave,LIGHTPHYS_VARIABLE_GROUPID,GroupID);
  99. csave.End_Chunk();
  100. return true;
  101. }
  102. bool LightPhysClass::Load (ChunkLoadClass &cload)
  103. {
  104. while (cload.Open_Chunk()) {
  105. switch(cload.Cur_Chunk_ID()) {
  106. case LIGHTPHYS_CHUNK_DECOPHYS:
  107. DecorationPhysClass::Load(cload);
  108. break;
  109. case LIGHTPHYS_CHUNK_VARIABLES:
  110. while (cload.Open_Micro_Chunk()) {
  111. switch(cload.Cur_Micro_Chunk_ID()) {
  112. READ_MICRO_CHUNK(cload,LIGHTPHYS_VARIABLE_VISSECTORID,VisSectorID);
  113. READ_MICRO_CHUNK(cload,LIGHTPHYS_VARIABLE_GROUPID,GroupID);
  114. }
  115. cload.Close_Micro_Chunk();
  116. }
  117. break;
  118. default:
  119. WWDEBUG_SAY(("Unhandled Chunk: 0x%X File: %s Line: %d\r\n",cload.Cur_Chunk_ID(),__FILE__,__LINE__));
  120. break;
  121. }
  122. cload.Close_Chunk();
  123. }
  124. //(gth) turn off the disabled flag, let the building re-set this when it updates its state.
  125. Set_Disabled(false);
  126. SaveLoadSystemClass::Register_Post_Load_Callback(this);
  127. return true;
  128. }
  129. void LightPhysClass::On_Post_Load(void)
  130. {
  131. // Set our cull box but don't let the culling system re-insert us.
  132. Set_Cull_Box(Model->Get_Bounding_Box(),true);
  133. }