| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- /*
- ** Command & Conquer Renegade(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /***********************************************************************************************
- *** 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 ***
- ***********************************************************************************************
- * *
- * Project Name : WWPhys *
- * *
- * $Archive:: /Commando/Code/wwphys/lightcull.cpp $*
- * *
- * Author:: Greg Hjelstrom *
- * *
- * $Modtime:: 4/02/01 12:23p $*
- * *
- * $Revision:: 18 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "lightcull.h"
- #include "lightphys.h"
- #include "ww3d.h"
- #include "rinfo.h"
- #include "chunkio.h"
- #include "wwphysids.h"
- #include "camera.h"
- /*
- ** Current version of the lightcull file format
- */
- const uint32 STATICLIGHTCULL_CURRENT_VERSION = 0x00010000;
- /*
- ** Chunk Id's used by the phys-aabtree code to save itself into a file
- */
- enum
- {
- STATICLIGHTCULL_CHUNK_VERSION = 0x00050001, // version wrapper, contains 32bit version #
- STATICLIGHTCULL_CHUNK_PARENT_CLASS_DATA = 0x00050104, // wraps the parent class's save data
- };
- /*
- ** StaticLightCullClass is a derived AABTree which assumes it contains LightPhysClasses
- ** these two functions encapsulate some typecasting which happens in a lot
- ** of places...
- */
- inline LightPhysClass * get_first_object(AABTreeNodeClass * node)
- {
- return (LightPhysClass *)(node->Object);
- }
- inline LightPhysClass * get_next_object(LightPhysClass * tile)
- {
- return (LightPhysClass *)(((AABTreeLinkClass *)tile->Get_Cull_Link())->NextObject);
- }
- /*
- ** Implementation of StaticLightCullClass
- */
- StaticLightCullClass::StaticLightCullClass(void)
- {
- }
- StaticLightCullClass::~StaticLightCullClass(void)
- {
- }
- void StaticLightCullClass::Add_Object(LightPhysClass * obj)
- {
- WWASSERT(PhysicsSceneClass::Get_Instance() != NULL);
- TypedAABTreeCullSystemClass<LightPhysClass>::Add_Object(obj);
- // (gth) not resetting vis when adding a new static light
- // PhysicsSceneClass::Get_Instance()->Reset_Vis();
- }
- void StaticLightCullClass::Remove_Object(LightPhysClass * obj)
- {
- WWASSERT(PhysicsSceneClass::Get_Instance() != NULL);
- TypedAABTreeCullSystemClass<LightPhysClass>::Remove_Object(obj);
- // (gth) not resetting vis when removing a static light
- // PhysicsSceneClass::Get_Instance()->Reset_Vis();
- }
- void StaticLightCullClass::Update_Culling(CullableClass * obj)
- {
- WWASSERT(PhysicsSceneClass::Get_Instance() != NULL);
- TypedAABTreeCullSystemClass<LightPhysClass>::Update_Culling(obj);
- // (gth) not resetting vis when moving a static light
- // PhysicsSceneClass::Get_Instance()->Reset_Vis();
- }
- void StaticLightCullClass::Save_Static_Data(ChunkSaveClass & csave)
- {
- csave.Begin_Chunk(STATICLIGHTCULL_CHUNK_PARENT_CLASS_DATA);
- TypedAABTreeCullSystemClass<LightPhysClass>::Save(csave);
- csave.End_Chunk();
- }
- void StaticLightCullClass::Load_Static_Data(ChunkLoadClass & cload)
- {
- while(cload.Open_Chunk())
- {
- switch(cload.Cur_Chunk_ID())
- {
-
- case STATICLIGHTCULL_CHUNK_PARENT_CLASS_DATA:
- {
- TypedAABTreeCullSystemClass<LightPhysClass>::Load(cload);
- }
- break;
- default:
- WWDEBUG_SAY(("Unhandled chunk type: %d in LightCullClass::Load\r\n",cload.Cur_Chunk_ID()));
- break;
- }
-
- cload.Close_Chunk();
- }
- }
-
- void StaticLightCullClass::Assign_Vis_IDs(void)
- {
- /*
- ** Allocate sector ID's for each light.
- */
- int nodecount = Partition_Node_Count();
- for (int i=0; i<nodecount; i++) {
- AABTreeNodeClass * node = IndexedNodes[i];
- LightPhysClass * obj = get_first_object(node);
- while(obj) {
- obj->Set_Vis_Sector_ID(PhysicsSceneClass::Get_Instance()->Allocate_Vis_Sector_ID());
- obj = get_next_object(obj);
- }
- }
- }
- void StaticLightCullClass::Merge_Vis_Sector_IDs(uint32 id0,uint32 id1)
- {
- /*
- ** Each lightphys object may have a vis sector id.
- ** Whenever we encounter one of these with id1, set it to id0.
- ** Whenever we encounter one with id > id1, subtract one from it.
- */
- for (int i=0; i<NodeCount; i++) {
- AABTreeNodeClass * node = IndexedNodes[i];
- LightPhysClass * obj = get_first_object(node);
- while (obj) {
- uint32 sector_id = obj->Get_Vis_Sector_ID();
- if (sector_id != 0xFFFFFFFF) {
- if (sector_id == id1) {
- sector_id = id0;
- } else if (sector_id > id1) {
- sector_id--;
- }
-
- obj->Set_Vis_Sector_ID(sector_id);
- }
- obj = get_next_object(obj);
- }
- }
- }
|