From 98ad4d7132a32716e534697287dbb5f9d1e6ebe4 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Fri, 25 Nov 2011 09:52:37 +0000 Subject: [PATCH] Factor out high-level 'add loop to sector' code into own function. git-svn-id: https://svn.eduke32.com/eduke32@2128 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/src/build.c | 182 ++++++++++++++++-------------- 1 file changed, 99 insertions(+), 83 deletions(-) diff --git a/polymer/eduke32/build/src/build.c b/polymer/eduke32/build/src/build.c index bea99872e..b946e7498 100644 --- a/polymer/eduke32/build/src/build.c +++ b/polymer/eduke32/build/src/build.c @@ -2642,6 +2642,99 @@ static int32_t vec2eq(const vec2_t *v1, const vec2_t *v2) return (v1->x==v2->x && v1->y==v2->y); } +// precondition: [numwalls, newnumwalls-1] form a new loop (may be of wrong orientation) +// returns: +// -1, -2: errors +// 0, 1: OK, 1 means it was an extended sector and an inner loop has been added automatically +static int32_t AddLoopToSector(int32_t k) +{ + int32_t extendedSector=0, firstwall, i, j; +#ifdef YAX_ENABLE + int16_t cbunch, fbunch; + int32_t newnumwalls2; + + yax_getbunches(k, &cbunch, &fbunch); + extendedSector = (cbunch>=0 || fbunch>=0); +#endif + j = newnumwalls-numwalls; +#ifdef YAX_ENABLE + newnumwalls2 = newnumwalls + j; + + if (extendedSector) + { + if ((cbunch>=0 && (sector[k].ceilingstat&2)) + || (fbunch>=0 && (sector[k].floorstat&2))) + { + message("Sloped extended sectors cannot be subdivided."); + newnumwalls--; + return -1; + } + + if (newnumwalls + j > MAXWALLS || numsectors+1 > MAXSECTORS) + { + message("Automatically adding inner sector to new extended sector would exceed limits!"); + newnumwalls--; + return -2; + } + } +#endif + if (clockdir(numwalls) == 0) + flipwalls(numwalls,newnumwalls); + + sector[k].wallnum += j; + for (i=k+1; i= firstwall) + wall[i].nextwall += j; + if (wall[i].point2 >= firstwall) + wall[i].point2 += j; + } +#ifdef YAX_ENABLE + yax_tweakwalls(firstwall, j); +#endif + + Bmemmove(&wall[firstwall+j], &wall[firstwall], (newnumwalls-firstwall)*sizeof(walltype)); + // add new loop to beginning of sector + Bmemmove(&wall[firstwall], &wall[newnumwalls], j*sizeof(walltype)); + + for (i=firstwall; i=0 || fbunch>=0); -#endif - j = newnumwalls-numwalls; -#ifdef YAX_ENABLE - newnumwalls2 = newnumwalls + j; - if (extendedSector) - { - if ((cbunch>=0 && (sector[k].ceilingstat&2)) - || (fbunch>=0 && (sector[k].floorstat&2))) - { - message("Sloped extended sectors cannot be subdivided."); - newnumwalls--; - goto end_space_handling; - } - - if (newnumwalls + j > MAXWALLS || numsectors+1 > MAXSECTORS) - { - message("Automatically adding inner sector to new extended sector would exceed limits!"); - newnumwalls--; - goto end_space_handling; - } - } -#endif - if (clockdir(numwalls) == 0) - flipwalls(numwalls,newnumwalls); - - sector[k].wallnum += j; - for (i=k+1; i= firstwall) - wall[i].nextwall += j; - if (wall[i].point2 >= firstwall) - wall[i].point2 += j; - } -#ifdef YAX_ENABLE - yax_tweakwalls(firstwall, j); -#endif - - Bmemmove(&wall[firstwall+j], &wall[firstwall], (newnumwalls-firstwall)*sizeof(walltype)); - Bmemmove(&wall[firstwall], &wall[newnumwalls], j*sizeof(walltype)); - - for (i=firstwall; i 0) printmessage16("Added inner loop to sector %d and made new inner sector", k); else #endif - printmessage16("Added inner loop to sector %d", k); + printmessage16("Added inner loop to sector %d", k); mkonwinvalid(); asksave = 1; }