From c7a291b113130e3c70591f507a9f318fbacbedb1 Mon Sep 17 00:00:00 2001 From: Kp Date: Mon, 24 Aug 2020 01:31:28 +0000 Subject: [PATCH] Move editor texture orientation handling to caller tmap1 cannot be rotated, so checking for it inside convert_to_d1_tmap_num is wrong. tmap2 can be rotated, and checking for it outside convert_to_d1_tmap_num is cleaner. --- similar/editor/mine.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/similar/editor/mine.cpp b/similar/editor/mine.cpp index f29569850..5625d294e 100644 --- a/similar/editor/mine.cpp +++ b/similar/editor/mine.cpp @@ -62,7 +62,7 @@ int New_file_format_save = 1; #if defined(DXX_BUILD_DESCENT_II) // Converts descent 2 texture numbers back to descent 1 texture numbers. // Only works properly when the full Descent 1 texture set (descent.pig) is available. -static short convert_to_d1_tmap_num(short tmap_num) +static uint16_t convert_to_d1_tmap_num(const uint16_t tmap_num) { switch (tmap_num) { @@ -307,17 +307,8 @@ static short convert_to_d1_tmap_num(short tmap_num) if (tmap_num < 635) return tmap_num - 141; if (tmap_num < 731) return tmap_num - 147; } - { // handle rare case where orientation != 0 - short tmap_num_part = tmap_num & TMAP_NUM_MASK; - short orient = tmap_num & ~TMAP_NUM_MASK; - if (orient != 0) - return orient | convert_to_d1_tmap_num(tmap_num_part); - else - { - Warning("can't convert unknown texture #%d to descent 1.\n", tmap_num_part); - return tmap_num; - } - } + Warning("can't convert unknown texture #%hu to descent 1.\n", tmap_num); + return tmap_num; } } #endif @@ -664,7 +655,10 @@ int save_mine_data_compiled(PHYSFS_File *SaveFile) { tmap_num = convert_to_d1_tmap_num(tmap_num); if (tmap_num2) - tmap_num2 = convert_to_d1_tmap_num(tmap_num2); + { + const auto orient = tmap_num2 & ~TMAP_NUM_MASK; + tmap_num2 = orient | convert_to_d1_tmap_num(tmap_num2 & TMAP_NUM_MASK); + } } #endif