From 480690aa1d366539b4de17ec17ab8b69dea0d594 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sat, 14 Jan 2012 14:48:30 +0000 Subject: [PATCH] Fix the Polymer hitches first encountered with Parkade. The cause was a combination of many factors. First, Polymer requires the start-drawing position to be inside the sector to draw (deviations lead to incorrect drawing). This was violated by the game, because it interpolated the current and next tic position without updating the sectnum, leading to inconsistencies especially when passing through narrow sectors. Polymer worked around it by doing an updatesector() each frame, however this works poorly for maps with overlapping geometry such as SoS or RoR. The solution to this is to add a new engine function, updatesector_onlynextwalls(), which searches the sectors (via nextsector) in breadth-first fashion instead of from 0 to numsectors-1, like updatesector does when it fails for the *immediate* nextwall neighbors. Internally, the breadt-first search helpers are moved into the engine. git-svn-id: https://svn.eduke32.com/eduke32@2256 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/build.h | 4 ++ polymer/eduke32/build/include/editor.h | 3 -- polymer/eduke32/build/src/build.c | 23 ----------- polymer/eduke32/build/src/engine.c | 57 ++++++++++++++++++++++++++ polymer/eduke32/build/src/polymer.c | 8 +++- 5 files changed, 67 insertions(+), 28 deletions(-) diff --git a/polymer/eduke32/build/include/build.h b/polymer/eduke32/build/include/build.h index c6923dc66..418c1e67e 100644 --- a/polymer/eduke32/build/include/build.h +++ b/polymer/eduke32/build/include/build.h @@ -576,6 +576,9 @@ void drawline256(int32_t x1, int32_t y1, int32_t x2, int32_t y2, char col); int32_t printext16(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, const char *name, char fontsize) ATTRIBUTE((nonnull(5))); void printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, const char *name, char fontsize) ATTRIBUTE((nonnull(5))); +void bfirst_search_init(int16_t *list, uint8_t *bitmap, int32_t *eltnumptr, int32_t maxnum, int16_t firstelt); +void bfirst_search_try(int16_t *list, uint8_t *bitmap, int32_t *eltnumptr, int16_t elt); + extern int32_t clipmoveboxtracenum; int32_t clipmove(vec3_t *vect, int16_t *sectnum, int32_t xvect, int32_t yvect, int32_t walldist, int32_t ceildist, int32_t flordist, uint32_t cliptype) ATTRIBUTE((nonnull(1,2))); int32_t clipinsidebox(int32_t x, int32_t y, int16_t wallnum, int32_t walldist); @@ -586,6 +589,7 @@ int32_t hitscan(const vec3_t *sv, int16_t sectnum, int32_t vx, int32_t vy, int int32_t neartag(int32_t xs, int32_t ys, int32_t zs, int16_t sectnum, int16_t ange, int16_t *neartagsector, int16_t *neartagwall, int16_t *neartagsprite, int32_t *neartaghitdist, int32_t neartagrange, uint8_t tagsearch) ATTRIBUTE((nonnull(6,7,8))); int32_t cansee(int32_t x1, int32_t y1, int32_t z1, int16_t sect1, int32_t x2, int32_t y2, int32_t z2, int16_t sect2); void updatesector(int32_t x, int32_t y, int16_t *sectnum) ATTRIBUTE((nonnull(3))); +void updatesector_onlynextwalls(int32_t x, int32_t y, int16_t *sectnum) ATTRIBUTE((nonnull(3))); void updatesectorexclude(int32_t x, int32_t y, int16_t *sectnum, const uint8_t *excludesectbitmap) ATTRIBUTE((nonnull(3))); void updatesectorz(int32_t x, int32_t y, int32_t z, int16_t *sectnum) ATTRIBUTE((nonnull(4))); int32_t inside(int32_t x, int32_t y, int16_t sectnum); diff --git a/polymer/eduke32/build/include/editor.h b/polymer/eduke32/build/include/editor.h index 726374da1..316609fbb 100644 --- a/polymer/eduke32/build/include/editor.h +++ b/polymer/eduke32/build/include/editor.h @@ -139,9 +139,6 @@ extern int32_t getinvdisplacement(int32_t *dx, int32_t *dy, int32_t dz) ATTRIBUT extern int32_t getscreenvdisp(int32_t bz, int32_t zoome); extern void setup_sideview_sincos(void); -extern void bfirst_search_init(int16_t *list, uint8_t *bitmap, int32_t *eltnumptr, int32_t maxnum, int16_t firstelt); -extern void bfirst_search_try(int16_t *list, uint8_t *bitmap, int32_t *eltnumptr, int16_t elt); - extern int32_t wallength(int16_t i); extern void fixrepeats(int16_t i); extern uint32_t getlenbyrep(int32_t len, int32_t repeat); diff --git a/polymer/eduke32/build/src/build.c b/polymer/eduke32/build/src/build.c index afc0fbda3..2da8d9d94 100644 --- a/polymer/eduke32/build/src/build.c +++ b/polymer/eduke32/build/src/build.c @@ -2421,29 +2421,6 @@ static int32_t compare_wall_coords(const void *w1, const void *w2) } while (0) -// breadth-first search helpers -void bfirst_search_init(int16_t *list, uint8_t *bitmap, int32_t *eltnumptr, int32_t maxnum, int16_t firstelt) -{ - Bmemset(bitmap, 0, (maxnum+7)>>3); - - list[0] = firstelt; - bitmap[firstelt>>3] |= (1<<(firstelt&7)); - *eltnumptr = 1; -} - -void bfirst_search_try(int16_t *list, uint8_t *bitmap, int32_t *eltnumptr, int16_t elt) -{ - if (elt < 0) - return; - - if ((bitmap[elt>>3]&(1<<(elt&7)))==0) - { - bitmap[elt>>3] |= (1<<(elt&7)); - list[*eltnumptr] = elt; - (*eltnumptr)++; - } -} - #ifdef YAX_ENABLE static int32_t collnumsects[2]; static int16_t collsectlist[2][MAXSECTORS]; diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index 068e1baeb..5d811fc99 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -12362,6 +12362,30 @@ int32_t pushmove(vec3_t *vect, int16_t *sectnum, } +// breadth-first search helpers +void bfirst_search_init(int16_t *list, uint8_t *bitmap, int32_t *eltnumptr, int32_t maxnum, int16_t firstelt) +{ + Bmemset(bitmap, 0, (maxnum+7)>>3); + + list[0] = firstelt; + bitmap[firstelt>>3] |= (1<<(firstelt&7)); + *eltnumptr = 1; +} + +void bfirst_search_try(int16_t *list, uint8_t *bitmap, int32_t *eltnumptr, int16_t elt) +{ + if (elt < 0) + return; + + if ((bitmap[elt>>3]&(1<<(elt&7)))==0) + { + bitmap[elt>>3] |= (1<<(elt&7)); + list[*eltnumptr] = elt; + (*eltnumptr)++; + } +} + + // // updatesector[z] // @@ -12401,6 +12425,39 @@ void updatesector(int32_t x, int32_t y, int16_t *sectnum) *sectnum = -1; } +void updatesector_onlynextwalls(int32_t x, int32_t y, int16_t *sectnum) +{ + static int16_t sectlist[MAXSECTORS]; + static uint8_t sectbitmap[MAXSECTORS>>3]; + int32_t nsecs, sectcnt, j; + + if ((unsigned)(*sectnum) >= (unsigned)numsectors) + return; + + bfirst_search_init(sectlist, sectbitmap, &nsecs, numsectors, *sectnum); + + for (sectcnt=0; sectcntwallptr; + int32_t endwall = sec->wallptr + sec->wallnum; + + if (inside(x,y, sectlist[sectcnt]) == 1) + { + *sectnum = sectlist[sectcnt]; + return; + } + + for (j=startwall; j= 0) + bfirst_search_try(sectlist, sectbitmap, &nsecs, wall[j].nextsector); + } + } + + *sectnum = -1; +} + void updatesectorexclude(int32_t x, int32_t y, int16_t *sectnum, const uint8_t *excludesectbitmap) { walltype *wal; diff --git a/polymer/eduke32/build/src/polymer.c b/polymer/eduke32/build/src/polymer.c index 9c843f260..fb4e73719 100644 --- a/polymer/eduke32/build/src/polymer.c +++ b/polymer/eduke32/build/src/polymer.c @@ -993,10 +993,11 @@ void polymer_drawrooms(int32_t daposx, int32_t daposy, int32_t da bglGetFloatv(GL_MODELVIEW_MATRIX, rootmodelviewmatrix); cursectnum = dacursectnum; - updatesector(daposx, daposy, &cursectnum); - + updatesector_onlynextwalls(daposx, daposy, &cursectnum); if ((cursectnum >= 0) && (cursectnum < numsectors)) dacursectnum = cursectnum; + else if (pr_verbosity>=2) + OSD_Printf("PR : got sector %d after update!\n", cursectnum); // unflag all sectors i = numsectors-1; @@ -1034,6 +1035,9 @@ void polymer_drawrooms(int32_t daposx, int32_t daposy, int32_t da (daposz > cursectflorz) || (daposz < cursectceilz)) { + if (!editstatus && pr_verbosity>=1) + OSD_Printf("PR : EXT sec=%d z=%d (%d, %d)\n", dacursectnum, daposz, cursectflorz, cursectceilz); + curmodelviewmatrix = rootmodelviewmatrix; i = numsectors-1; while (i >= 0)