From e1cd0dc588087933c0c93bda132e89781387af8c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 19 May 2017 16:31:44 +0200 Subject: [PATCH] - major optimization on carry scroller code. The old version was checking every single actor in every single sector for being affected by a carry scroller if there was so much as a single such scroller in the map. Changed it so that the scroll thinker flags all actors in the affected sectors so that these expensive calculations can be skipped for everything else. This change and reduce think time by 1/3 on maps like ZDCMP2 (on the test machine it went down from 6 ms to 4 ms on this map.) --- src/actor.h | 1 + src/p_mobj.cpp | 9 ++++++++- src/p_scroll.cpp | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/actor.h b/src/actor.h index 043f07ae5..be3f28ec6 100644 --- a/src/actor.h +++ b/src/actor.h @@ -401,6 +401,7 @@ enum ActorFlag7 enum ActorFlag8 { MF8_FRIGHTENING = 0x00000001, // for those moments when halloween just won't do + MF8_INSCROLLSEC = 0x00000002, // actor is partially inside a scrolling sector }; // --- mobj.renderflags --- diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 2e16347db..1fb7e259d 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -4098,6 +4098,7 @@ void AActor::Tick () CheckPortalTransition(false); LinkToWorld(&ctx); } + flags8 &= MF8_INSCROLLSEC; } else { @@ -4250,12 +4251,16 @@ void AActor::Tick () // [RH] Consider carrying sectors here DVector2 cumm(0, 0); - if ((level.Scrolls.Size() != 0 || player != NULL) && !(flags & MF_NOCLIP) && !(flags & MF_NOSECTOR)) + + if ((((flags8 & MF8_INSCROLLSEC) && level.Scrolls.Size() > 0) || player != NULL) && !(flags & MF_NOCLIP) && !(flags & MF_NOSECTOR)) { double height, waterheight; // killough 4/4/98: add waterheight const msecnode_t *node; int countx, county; + // Clear the flag for the next frame. + flags8 &= MF8_INSCROLLSEC; + // killough 3/7/98: Carry things on floor // killough 3/20/98: use new sector list which reflects true members // killough 3/27/98: fix carrier bug @@ -5079,6 +5084,8 @@ AActor *AActor::StaticSpawn (PClassActor *type, const DVector3 &pos, replace_t a { level.total_secrets++; } + // force scroller check in the first tic. + actor->flags8 |= MF8_INSCROLLSEC; return actor; } diff --git a/src/p_scroll.cpp b/src/p_scroll.cpp index f2661a2a1..d8666d9a7 100644 --- a/src/p_scroll.cpp +++ b/src/p_scroll.cpp @@ -256,6 +256,11 @@ void DScroller::Tick () case EScroll::sc_carry: level.Scrolls[m_Affectee].X += dx; level.Scrolls[m_Affectee].Y += dy; + // mark all potentially affected things here so that the very expensive calculation loop in AActor::Tick does not need to run for actors which do not touch a scrolling sector. + for (auto n = level.sectors[m_Affectee].touching_thinglist; n; n = n->m_snext) + { + n->m_thing->flags8 |= MF8_INSCROLLSEC; + } break; case EScroll::sc_carry_ceiling: // to be added later