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

Function ReadTerrainTmapFlagChunk

Descent3/LoadLevel.cpp:3364–3433  ·  view source on GitHub ↗

Reads the tmaps of the terrain, plus flags

Source from the content-addressed store, hash-verified

3362
3363// Reads the tmaps of the terrain, plus flags
3364void ReadTerrainTmapFlagChunk(CFILE *fp, int version) {
3365 int i, t;
3366
3367 if (version <= 31) {
3368 for (i = 0; i < TERRAIN_DEPTH * TERRAIN_WIDTH; i++)
3369 cf_ReadShort(fp);
3370 for (i = 0; i < TERRAIN_DEPTH * TERRAIN_WIDTH; i++)
3371 cf_ReadShort(fp);
3372
3373 if (version >= 16) {
3374 for (i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++)
3375 Terrain_seg[i].flags = cf_ReadByte(fp);
3376
3377 for (i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++)
3378 cf_ReadByte(fp);
3379 for (i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++)
3380 cf_ReadByte(fp);
3381 } else {
3382 for (i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++) {
3383 for (t = 0; t < 4; t++) {
3384 cf_ReadByte(fp);
3385 cf_ReadByte(fp);
3386 }
3387 }
3388 }
3389 } else {
3390 uint8_t *byte_vals = (uint8_t *)mem_malloc(TERRAIN_DEPTH * TERRAIN_WIDTH);
3391 uint16_t *short_vals = (uint16_t *)mem_malloc(2 * TERRAIN_DEPTH * TERRAIN_WIDTH);
3392
3393 if (version < 102) {
3394 // Read tmap1
3395 ReadCompressionShort(fp, short_vals, TERRAIN_DEPTH * TERRAIN_WIDTH);
3396 // Read tmap2
3397 ReadCompressionShort(fp, short_vals, TERRAIN_DEPTH * TERRAIN_WIDTH);
3398 } else {
3399 ReadCompressionShort(fp, short_vals, TERRAIN_TEX_DEPTH * TERRAIN_TEX_WIDTH);
3400 for (i = 0; i < TERRAIN_TEX_DEPTH * TERRAIN_TEX_WIDTH; i++) {
3401 Terrain_tex_seg[i].tex_index = texture_xlate[short_vals[i]];
3402
3403 // Check for failed xlate
3404 if (Terrain_tex_seg[i].tex_index == -1) {
3405 Terrain_tex_seg[i].tex_index = 0;
3406 }
3407 }
3408
3409 ReadCompressionByte(fp, byte_vals, TERRAIN_TEX_DEPTH * TERRAIN_TEX_WIDTH);
3410 for (i = 0; i < TERRAIN_TEX_DEPTH * TERRAIN_TEX_WIDTH; i++) {
3411 Terrain_tex_seg[i].rotation = byte_vals[i];
3412 if ((Terrain_tex_seg[i].rotation >> 4) == 0)
3413 Terrain_tex_seg[i].rotation |= (1 << 4);
3414 }
3415 }
3416
3417 // Read flags
3418 ReadCompressionByte(fp, byte_vals, TERRAIN_DEPTH * TERRAIN_WIDTH);
3419 for (i = 0; i < TERRAIN_DEPTH * TERRAIN_WIDTH; i++)
3420 Terrain_seg[i].flags = byte_vals[i];
3421

Callers 1

ReadTerrainChunksFunction · 0.85

Calls 4

cf_ReadShortFunction · 0.85
cf_ReadByteFunction · 0.85
ReadCompressionShortFunction · 0.85
ReadCompressionByteFunction · 0.85

Tested by

no test coverage detected