// Perform the merge. // // The merge code creates a new lumpinfo list, adding entries from the // IWAD first followed by the PWAD. // // For the IWAD: // * Flats are added. If a flat with the same name is in the PWAD, // it is ignored(deleted). At the end of the section, all flats in the // PWAD are inserted. This is consistent with the behavior of // deutex/deusf. // * Sprites are added. The "replace list" is generated before the merge // from the list of sprites in the PWAD. Any sprites in the IWAD found // to match the replace list are removed. At the end of the section, // the sprites from the PWAD are inserted. // // For the PWAD: // * All Sprites and Flats are ignored, with the assumption they have // already been merged into the IWAD's sections. static void DoMerge(void) { section_t current_section; lumpinfo_t *newlumps; int num_newlumps; int lumpindex; int i, n; // Can't ever have more lumps than we already have newlumps = (lumpinfo_t *)malloc(sizeof(lumpinfo_t) * numlumps); num_newlumps = 0; // Add IWAD lumps current_section = SECTION_NORMAL; for (i = 0; i < iwad.numlumps; ++i) { lumpinfo_t *lump = &iwad.lumps[i]; switch (current_section) { case SECTION_NORMAL: if (!strncasecmp(lump->name, "F_START", 8)) current_section = SECTION_FLATS; else if (!strncasecmp(lump->name, "S_START", 8)) current_section = SECTION_SPRITES; newlumps[num_newlumps++] = *lump; break; case SECTION_FLATS: // Have we reached the end of the section? if (!strncasecmp(lump->name, "F_END", 8)) { // Add all new flats from the PWAD to the end // of the section for (n = 0; n < pwad_flats.numlumps; ++n) newlumps[num_newlumps++] = pwad_flats.lumps[n]; newlumps[num_newlumps++] = *lump; // back to normal reading current_section = SECTION_NORMAL; } else { // If there is a flat in the PWAD with the same name, // do not add it now. All PWAD flats are added to the // end of the section. Otherwise, if it is only in the // IWAD, add it now lumpindex = FindInList(&pwad_flats, lump->name); if (lumpindex < 0) newlumps[num_newlumps++] = *lump; } break; case SECTION_SPRITES: // Have we reached the end of the section? if (!strncasecmp(lump->name, "S_END", 8)) { // add all the pwad sprites for (n = 0; n < pwad_sprites.numlumps; ++n) { if (SpriteLumpNeeded(&pwad_sprites.lumps[n])) newlumps[num_newlumps++] = pwad_sprites.lumps[n]; } // copy the ending newlumps[num_newlumps++] = *lump; // back to normal reading current_section = SECTION_NORMAL; } else { // Is this lump holding a sprite to be replaced in the // PWAD? If so, wait until the end to add it. if (SpriteLumpNeeded(lump)) newlumps[num_newlumps++] = *lump; } break; } } // Add PWAD lumps current_section = SECTION_NORMAL; for (i = 0; i < pwad.numlumps; ++i) { lumpinfo_t *lump = &pwad.lumps[i]; switch (current_section) { case SECTION_NORMAL: if (!strncasecmp(lump->name, "F_START", 8) || !strncasecmp(lump->name, "FF_START", 8)) current_section = SECTION_FLATS; else if (!strncasecmp(lump->name, "S_START", 8) || !strncasecmp(lump->name, "SS_START", 8)) current_section = SECTION_SPRITES; else { // Don't include the headers of sections newlumps[num_newlumps++] = *lump; } break; case SECTION_FLATS: // PWAD flats are ignored (already merged) if (!strncasecmp(lump->name, "FF_END", 8) || !strncasecmp(lump->name, "F_END", 8)) { // end of section current_section = SECTION_NORMAL; } break; case SECTION_SPRITES: // PWAD sprites are ignored (already merged) if (!strncasecmp(lump->name, "SS_END", 8) || !strncasecmp(lump->name, "S_END", 8)) { // end of section current_section = SECTION_NORMAL; } break; } } // Switch to the new lumpinfo, and free the old one free(lumpinfo); lumpinfo = newlumps; numlumps = num_newlumps; }
// Perform the merge. // // The merge code creates a new lumpinfo list, adding entries from the // IWAD first followed by the PWAD. // // For the IWAD: // * Flats are added. If a flat with the same name is in the PWAD, // it is ignored (deleted). At the end of the section, all flats in the // PWAD are inserted. This is consistent with the behavior of // deutex/deusf. // * Sprites are added. The "replace list" is generated before the merge // from the list of sprites in the PWAD. Any sprites in the IWAD found // to match the replace list are removed. At the end of the section, // the sprites from the PWAD are inserted. // // For the PWAD: // * All Sprites and Flats are ignored, with the assumption they have // already been merged into the IWAD's sections. static void DoMerge(void) { section_t current_section; lumpinfo_t **newlumps; int num_newlumps; int lumpindex; // Can't ever have more lumps than we already have newlumps = calloc(numlumps, sizeof(lumpinfo_t *)); num_newlumps = 0; // Add IWAD lumps current_section = SECTION_NORMAL; for (int i = 0; i < iwad.numlumps; i++) { lumpinfo_t *lump = iwad.lumps[i]; switch (current_section) { case SECTION_NORMAL: if (!strncasecmp(lump->name, "F_START", 8)) current_section = SECTION_FLATS; else if (!strncasecmp(lump->name, "S_START", 8)) current_section = SECTION_SPRITES; newlumps[num_newlumps++] = lump; break; case SECTION_FLATS: // Have we reached the end of the section? if (!strncasecmp(lump->name, "F_END", 8)) { // Add all new flats from the PWAD to the end // of the section for (int n = 0; n < pwad_flats.numlumps; n++) newlumps[num_newlumps++] = pwad_flats.lumps[n]; newlumps[num_newlumps++] = lump; // back to normal reading current_section = SECTION_NORMAL; } else { // If there is a flat in the PWAD with the same name, // do not add it now. All PWAD flats are added to the // end of the section. Otherwise, if it is only in the // IWAD, add it now lumpindex = FindInList(&pwad_flats, lump->name); if (lumpindex < 0) newlumps[num_newlumps++] = lump; } break; case SECTION_SPRITES: // Have we reached the end of the section? if (!strncasecmp(lump->name, "S_END", 8)) { // add all the PWAD sprites for (int n = 0; n < pwad_sprites.numlumps; n++) if (SpriteLumpNeeded(pwad_sprites.lumps[n])) newlumps[num_newlumps++] = pwad_sprites.lumps[n]; // copy the ending newlumps[num_newlumps++] = lump; // back to normal reading current_section = SECTION_NORMAL; } else { // Is this lump holding a sprite to be replaced in the // PWAD? If so, wait until the end to add it. if (SpriteLumpNeeded(lump)) newlumps[num_newlumps++] = lump; } break; case SECTION_HIDEF: break; } } // Add PWAD lumps current_section = SECTION_NORMAL; for (int i = 0, histart; i < pwad.numlumps; i++) { lumpinfo_t *lump = pwad.lumps[i]; switch (current_section) { case SECTION_NORMAL: if (!strncasecmp(lump->name, "F_START", 8) || !strncasecmp(lump->name, "FF_START", 8)) current_section = SECTION_FLATS; else if (!strncasecmp(lump->name, "S_START", 8) || !strncasecmp(lump->name, "SS_START", 8)) current_section = SECTION_SPRITES; else if (!strncasecmp(lump->name, "HI_START", 8)) { current_section = SECTION_HIDEF; histart = i; } else // Don't include the headers of sections newlumps[num_newlumps++] = lump; break; case SECTION_FLATS: // PWAD flats are ignored (already merged) if (!strncasecmp(lump->name, "FF_END", 8) || !strncasecmp(lump->name, "F_END", 8)) // end of section current_section = SECTION_NORMAL; break; case SECTION_SPRITES: // PWAD sprites are ignored (already merged) if (!strncasecmp(lump->name, "SS_END", 8) || !strncasecmp(lump->name, "S_END", 8)) // end of section current_section = SECTION_NORMAL; break; case SECTION_HIDEF: if (!strncasecmp(lump->name, "HI_END", 8)) { int hiend = i - histart - 1; current_section = SECTION_NORMAL; if (hiend) { if (hiend == 1) C_Warning("The patch between the <b>HI_START</b> and <b>HI_END</b> markers will be ignored."); else C_Warning("The %s patches between the <b>HI_START</b> and <b>HI_END</b> markers will be ignored.", commify(hiend)); } } break; } } // Switch to the new lumpinfo, and free the old one free(lumpinfo); lumpinfo = newlumps; numlumps = num_newlumps; }