diff --git a/polymer/eduke32/package/sdk/samples/a.m32 b/polymer/eduke32/package/sdk/samples/a.m32 index 2db596b39..98524326d 100644 --- a/polymer/eduke32/package/sdk/samples/a.m32 +++ b/polymer/eduke32/package/sdk/samples/a.m32 @@ -1563,6 +1563,53 @@ defstate sanitize_underwater_sprites printmessage16 "Set xvel=1 on highlighted wall/floor sprites" ends +define BZ_MAX 8388608 + +defstate uniformceil + var avgz n + + for i selsectors + { + ifand sector[i].ceilingstat 2 xor sector[i].ceilingstat 2 + add avgz sector[i].ceilingz + add n 1 + } + + ife n 0 break + + div avgz n + and avgz 0xfffffc00 // round to one PGUP/PNDN unit (1024 z units) + + ifvarge avgz -BZ_MAX ifvarle avgz BZ_MAX nullop + else quote "ERROR: average z value outside [-8388608 .. 8388608]" // BZ_MAX + + for i selsectors + set sector[i].ceilingz avgz +ends + +// XXX: CODEDUP +defstate uniformfloor + var avgz n + + for i selsectors + { + ifand sector[i].floorstat 2 xor sector[i].floorstat 2 + add avgz sector[i].floorz + add n 1 + } + + ife n 0 break + + div avgz n + and avgz 0xfffffc00 // round to one PGUP/PNDN unit (1024 z units) + + ifvarge avgz -BZ_MAX ifvarle avgz BZ_MAX nullop + else quote "ERROR: average z value outside [-8388608 .. 8388608]" // BZ_MAX + + for i selsectors + set sector[i].floorz avgz +ends + // This must be *compiled* with script_expertmode /* defstate setstartpos diff --git a/polymer/eduke32/source/m32exec.c b/polymer/eduke32/source/m32exec.c index 60e1142f0..ed11437cb 100644 --- a/polymer/eduke32/source/m32exec.c +++ b/polymer/eduke32/source/m32exec.c @@ -149,7 +149,7 @@ void VM_OnEvent(register int32_t iEventID, register int32_t iActor) int32_t localvars[M32_LOCALS_FIXEDNUM]; #endif - // needed since any read access before initialization would cause undefined behaviour + // Initialize 'state'-local variables to 0. if (aEventNumLocals[iEventID] > 0) Bmemset(localvars, 0, aEventNumLocals[iEventID]*sizeof(int32_t));