diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index 8754e2603..f62bc37fe 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -2330,8 +2330,8 @@ static int32_t colnext[256]; static char coldist[8] = {0,1,2,3,4,3,2,1}; static int32_t colscan[27]; -static int16_t clipnum, hitwalls[4]; -const int32_t hitscangoalx = (1<<29)-1, hitscangoaly = (1<<29)-1; +static int16_t clipnum; +static const int32_t hitscangoalx = (1<<29)-1, hitscangoaly = (1<<29)-1; #ifdef USE_OPENGL int32_t hitallsprites = 0; #endif @@ -13611,7 +13611,7 @@ int32_t clipmove(vec3_t *pos, int16_t *sectnum, int32_t i, j, k, tempint1, tempint2; int32_t x1, y1, x2, y2; int32_t dax, day; - int32_t hitwall, cnt, retval=0; + int32_t retval=0; spritetype *curspr=NULL; // non-NULL when handling sprite with sector-like clipping int32_t curidx=-1, clipsectcnt, clipspritecnt; @@ -13933,8 +13933,9 @@ int32_t clipmove(vec3_t *pos, int16_t *sectnum, } #endif - hitwall = 0; - cnt = clipmoveboxtracenum; + int32_t hitwalls[4], hitwall; + int32_t cnt = clipmoveboxtracenum; + do { int32_t intx=goalx, inty=goaly; @@ -13977,7 +13978,8 @@ int32_t clipmove(vec3_t *pos, int16_t *sectnum, xvect = (goalx-intx)<<14; yvect = (goaly-inty)<<14; - if (cnt == clipmoveboxtracenum) retval = clipobjectval[hitwall]; + if (cnt == clipmoveboxtracenum) + retval = (uint16_t)clipobjectval[hitwall]; hitwalls[cnt] = hitwall; } cnt--; diff --git a/polymer/eduke32/source/lunatic/control.lua b/polymer/eduke32/source/lunatic/control.lua index 64ac203a7..6dce0390d 100644 --- a/polymer/eduke32/source/lunatic/control.lua +++ b/polymer/eduke32/source/lunatic/control.lua @@ -1539,7 +1539,7 @@ end function _clipmovex(x, y, z, sectnum, xv, yv, wd, cd, fd, clipmask, noslidep) check_sector_idx(sectnum) local ipos = ivec3(x, y, z) - local sect = ffi.new("int16_t [1]") + local sect = ffi.new("int16_t [1]", sectnum) local ret = ffiC.clipmovex(ipos, sect, xv, yv, wd, cd, fd, clipmask, noslidep) -- Return: clipmovex() return value; updated x, y, sectnum return ret, ipos.x, ipos.y, sect[0] diff --git a/polymer/eduke32/source/lunatic/lunacon.lua b/polymer/eduke32/source/lunatic/lunacon.lua index c6323f6a8..73089ff1b 100644 --- a/polymer/eduke32/source/lunatic/lunacon.lua +++ b/polymer/eduke32/source/lunatic/lunacon.lua @@ -3546,6 +3546,8 @@ local Grammar = Pat{ + Range("09")^1) ) / parse_number, + -- TODO: negated gamevars. Currently, "-var" is parsed as a negated label. + t_identifier_all = lpeg.C(t_broken_identifier + t_good_identifier), -- NOTE: -conl.keyword alone would be wrong, e.g. "state breakobject": -- NOTE 2: The + "[" is so that stuff like diff --git a/polymer/eduke32/source/lunatic/test/checknearwall.con b/polymer/eduke32/source/lunatic/test/checknearwall.con new file mode 100644 index 000000000..34e2756b4 --- /dev/null +++ b/polymer/eduke32/source/lunatic/test/checknearwall.con @@ -0,0 +1,86 @@ + +// Inputs to "state checknearwall". +gamevar wd 128 0 // wall distance +gamevar cfd 1024 0 // ceiling/floor distance + +// Outputs of "state checknearwall". +gamevar hitwall -1 0 + +// Temporary variables. +gamevar tmp 0 0 +gamevar ret 0 0 +gamevar x 0 0 +gamevar y 0 0 +gamevar z 0 0 +gamevar sectnum 0 0 + +define CM_BLK_WAL 1 + +state getcoords + setvarvar x sprite[THISACTOR].x + setvarvar y sprite[THISACTOR].y + setvarvar z sprite[THISACTOR].z + setvarvar sectnum sprite[THISACTOR].sectnum +ends + +// Inputs: (wd, cfd) +// Returns: hitwall +// -1: hit no wall +// >=0: hit that wall +state checknearwall + setvar hitwall -1 + + setvarvar tmp wd, shiftvarl tmp 14 + + state getcoords + clipmovenoslide ret (x, y, z, sectnum) (tmp, 0) (wd, cfd, cfd) CM_BLK_WAL + ifvarn ret 0 { setvarvar hitwall ret, subvar hitwall 32768, break } + + state getcoords + clipmovenoslide ret (x, y, z, sectnum) (0, tmp) (wd, cfd, cfd) CM_BLK_WAL + ifvarn ret 0 { setvarvar hitwall ret, subvar hitwall 32768, break } + + mulvar tmp -1 + + state getcoords + clipmovenoslide ret (x, y, z, sectnum) (tmp, 0) (wd, cfd, cfd) CM_BLK_WAL + ifvarn ret 0 { setvarvar hitwall ret, subvar hitwall 32768, break } + + state getcoords + clipmovenoslide ret (x, y, z, sectnum) (0, tmp) (wd, cfd, cfd) CM_BLK_WAL + ifvarn ret 0 { setvarvar hitwall ret, subvar hitwall 32768, break } +ends + +////////// Example usage ////////// + +onevent EVENT_PROCESSINPUT + state checknearwall +endevent + + +define Q_tmp 500 +definequote Q_tmp + +define Q_no 501 +definequote Q_no Hit no wall + +define Q_yes 502 +definequote Q_yes Hit wall %d + +define Q_info 503 +definequote Q_info pos: %d %d %d sect: %d + +onevent EVENT_DISPLAYREST + qsprintf Q_tmp Q_info, x y z sectnum + minitext (100, 8) Q_tmp (0, 0) + + ifvarn hitwall -1 + { + qsprintf Q_tmp Q_yes hitwall + minitext (100, 16) Q_tmp (0, 0) + } + else + { + minitext (100, 16) Q_no (0, 0) + } +endevent