MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / ReadTerrainChunks

Function ReadTerrainChunks

Descent3/LoadLevel.cpp:3437–3476  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3435// MUST BE SAVED BEFORE OBJECTS because of ResetTerrain
3436
3437void ReadTerrainChunks(CFILE *fp, int version) {
3438 char chunk_name[4];
3439 int terr_chunk_start, terr_chunk_size;
3440 int done = 0;
3441
3442 ResetTerrain();
3443
3444 while (!done) {
3445 cf_ReadBytes((uint8_t *)chunk_name, 4, fp);
3446 terr_chunk_start = cftell(fp);
3447 terr_chunk_size = cf_ReadInt(fp);
3448
3449 LoadLevelProgress(LOAD_PROGRESS_LOADING_LEVEL,
3450 (filelen) ? (float)(terr_chunk_start + terr_chunk_size) / (float)filelen : 0.0f, NULL);
3451
3452 if (ISCHUNK(CHUNK_TERRAIN_HEIGHT)) {
3453 ReadTerrainHeightChunk(fp, version);
3454 } else if (ISCHUNK(CHUNK_TERRAIN_TMAPS_FLAGS)) {
3455 ReadTerrainTmapFlagChunk(fp, version);
3456 } else if (ISCHUNK(CHUNK_TERRAIN_SKY)) {
3457 ReadTerrainSkyAndLightChunk(fp, version);
3458 } else if (ISCHUNK(CHUNK_TERRAIN_END)) {
3459 done = 1;
3460 cfseek(fp, terr_chunk_start + terr_chunk_size, SEEK_SET);
3461 continue;
3462 }
3463 // else unknown chunk
3464 cfseek(fp, terr_chunk_start + terr_chunk_size, SEEK_SET);
3465 }
3466
3467 // Generate needed info
3468 BuildMinMaxTerrain();
3469 BuildTerrainNormals();
3470 UpdateTerrainLightmaps();
3471
3472#if (defined(EDITOR) || defined(NEWEDITOR))
3473 memset(TerrainSelected, 0, TERRAIN_WIDTH * TERRAIN_DEPTH);
3474 Num_terrain_selected = 0;
3475#endif
3476}
3477
3478// Read the texture names & build the xlate table
3479void ReadTextureList(CFILE *ifile) { BuildXlateTable(ifile, FindTextureName, texture_xlate, MAX_TEXTURES, -1); }

Callers 1

ifFunction · 0.85

Calls 12

ResetTerrainFunction · 0.85
cf_ReadBytesFunction · 0.85
cftellFunction · 0.85
cf_ReadIntFunction · 0.85
LoadLevelProgressFunction · 0.85
ReadTerrainHeightChunkFunction · 0.85
ReadTerrainTmapFlagChunkFunction · 0.85
cfseekFunction · 0.85
BuildMinMaxTerrainFunction · 0.85
BuildTerrainNormalsFunction · 0.85
UpdateTerrainLightmapsFunction · 0.85

Tested by

no test coverage detected