| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- /*
- ** 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 : leveledit *
- * *
- * $Archive:: /Commando/Code/wwphys/terrainmaterial.cpp $*
- * *
- * Author:: Patrick Smith *
- * *
- * $Modtime:: 3/08/02 2:52p $*
- * *
- * $Revision:: 4 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "terrainmaterial.h"
- #include "texture.h"
- #include "assetmgr.h"
- #include "chunkio.h"
- #include "w3d_file.h"
- ////////////////////////////////////////////////////////////////
- // Local constants
- ////////////////////////////////////////////////////////////////
- enum
- {
- CHUNKID_VARIABLES = 0x02261040,
- };
- enum
- {
- VARID_XXXXXXX_XXXX = 0x01,
- VARID_METERS_PER_TILE,
- VARID_TEXTURE_NAME,
- VARID_MIRRORED_UVS,
- VARID_SURFACE_TYPE,
- };
- //////////////////////////////////////////////////////////////////////
- //
- // TerrainMaterialClass
- //
- //////////////////////////////////////////////////////////////////////
- TerrainMaterialClass::TerrainMaterialClass (void) :
- Texture (NULL),
- MetersPerTile (10.0F),
- SurfaceType (0),
- AreUVsMirrored (false)
- {
- return ;
- }
- //////////////////////////////////////////////////////////////////////
- //
- // ~TerrainMaterialClass
- //
- //////////////////////////////////////////////////////////////////////
- TerrainMaterialClass::~TerrainMaterialClass (void)
- {
- //
- // Release the texture
- //
- REF_PTR_RELEASE (Texture);
- return ;
- }
- //////////////////////////////////////////////////////////////////////
- //
- // Set_Texture
- //
- //////////////////////////////////////////////////////////////////////
- void
- TerrainMaterialClass::Set_Texture (const char *texture_name)
- {
- //
- // Release the old texture
- //
- REF_PTR_RELEASE (Texture);
-
- //
- // Load the new texture
- //
- TextureName = texture_name;
- #ifndef PARAM_EDITING_ON
- const char *dir_delim = ::strrchr (texture_name, '\\');
- if (dir_delim != NULL) {
- TextureName = dir_delim + 1;
- }
- #endif
- Texture = WW3DAssetManager::Get_Instance ()->Get_Texture (TextureName);
- return ;
- }
- //////////////////////////////////////////////////////////////////////
- //
- // Save
- //
- //////////////////////////////////////////////////////////////////////
- void
- TerrainMaterialClass::Set_Surface_Type (int type)
- {
- if ((type >= 0) && (type < SURFACE_TYPE_MAX)) {
- SurfaceType = type;
- }
- }
- //////////////////////////////////////////////////////////////////////
- //
- // Save
- //
- //////////////////////////////////////////////////////////////////////
- bool
- TerrainMaterialClass::Save (ChunkSaveClass &csave)
- {
- //
- // Write the variables
- //
- csave.Begin_Chunk (CHUNKID_VARIABLES);
- WRITE_MICRO_CHUNK_WWSTRING (csave, VARID_TEXTURE_NAME, TextureName);
- WRITE_MICRO_CHUNK (csave, VARID_METERS_PER_TILE, MetersPerTile);
- WRITE_MICRO_CHUNK (csave, VARID_MIRRORED_UVS, AreUVsMirrored);
- WRITE_MICRO_CHUNK (csave, VARID_SURFACE_TYPE, SurfaceType);
- csave.End_Chunk ();
- return true;
- }
- //////////////////////////////////////////////////////////////////////
- //
- // Load
- //
- //////////////////////////////////////////////////////////////////////
- bool
- TerrainMaterialClass::Load (ChunkLoadClass &cload)
- {
- while (cload.Open_Chunk ()) {
- switch (cload.Cur_Chunk_ID ()) {
-
- //
- // Load all the variables from this chunk
- //
- case CHUNKID_VARIABLES:
- Load_Variables (cload);
- break;
- }
- cload.Close_Chunk ();
- }
- //
- // Load the texture into memory
- //
- Set_Texture (TextureName);
- return true;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Load_Variables
- //
- ////////////////////////////////////////////////////////////////
- void
- TerrainMaterialClass::Load_Variables (ChunkLoadClass &cload)
- {
- while (cload.Open_Micro_Chunk ()) {
- switch (cload.Cur_Micro_Chunk_ID ()) {
- //
- // Read each of the microchunks
- //
- READ_MICRO_CHUNK_WWSTRING (cload, VARID_TEXTURE_NAME, TextureName);
- READ_MICRO_CHUNK (cload, VARID_METERS_PER_TILE, MetersPerTile);
- READ_MICRO_CHUNK (cload, VARID_MIRRORED_UVS, AreUVsMirrored);
- READ_MICRO_CHUNK (cload, VARID_SURFACE_TYPE, SurfaceType);
- }
- cload.Close_Micro_Chunk ();
- }
- //
- // Enforcing that the surface type is valid; the game will assert this later otherwise...
- // Also fixed it on the editor side, surface types are initialized to zero.
- //
- if ((SurfaceType < 0) || (SurfaceType >= SURFACE_TYPE_MAX)) {
- SurfaceType = 0;
- }
- return ;
- }
|