From 58a091067fe4a71b7424440715522bb4e60ba5fd Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 15 Nov 2021 22:44:16 +0100 Subject: [PATCH] - use provided sector/wall iterators in cacheit functions --- source/core/iterators.h | 12 ++++++++++++ source/games/duke/src/dukeactor.h | 4 ++++ source/games/duke/src/premap_d.cpp | 22 ++++++++++------------ source/games/duke/src/premap_r.cpp | 20 +++++++++----------- 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/source/core/iterators.h b/source/core/iterators.h index 7d9e3e57b..4761b3b75 100644 --- a/source/core/iterators.h +++ b/source/core/iterators.h @@ -51,6 +51,12 @@ public: assert(stat >= 0 && stat < MAXSECTORS); next = headspritesect[stat]; } + + SectIterator(sectortype* sect) + { + assert(sect); + next = headspritesect[sect - sector]; + } void Reset(int stat) { @@ -58,6 +64,12 @@ public: next = headspritesect[stat]; } + void Reset(sectortype* sect) + { + assert(sect); + next = headspritesect[sect - sector]; + } + int NextIndex() { int n = next; diff --git a/source/games/duke/src/dukeactor.h b/source/games/duke/src/dukeactor.h index 7eef940b7..8b4373acb 100644 --- a/source/games/duke/src/dukeactor.h +++ b/source/games/duke/src/dukeactor.h @@ -33,6 +33,10 @@ public: { } + DukeSectIterator(sectortype* stat) : SectIterator(stat) + { + } + DDukeActor *Next() { int n = NextIndex(); diff --git a/source/games/duke/src/premap_d.cpp b/source/games/duke/src/premap_d.cpp index 2b81990cf..d95428d09 100644 --- a/source/games/duke/src/premap_d.cpp +++ b/source/games/duke/src/premap_d.cpp @@ -233,29 +233,27 @@ static void cachegoodsprites(void) void cacheit_d(void) { if (!r_precache) return; - int i; cachegoodsprites(); - for (i = 0; i < numwalls; i++) + for (auto& wal : walls()) { - tloadtile(wall[i].picnum, wall[i].pal); - if (wall[i].overpicnum >= 0) - tloadtile(wall[i].overpicnum, wall[i].pal); + tloadtile(wal.picnum, wal.pal); + if (wal.overpicnum >= 0) + tloadtile(wal.overpicnum, wal.pal); } - for (i = 0; i < numsectors; i++) + for (auto& sect : sectors()) { - auto sectp = §or[i]; - tloadtile(sectp->floorpicnum, sectp->floorpal); - tloadtile(sectp->ceilingpicnum, sectp->ceilingpal); - if (sectp->ceilingpicnum == LA) + tloadtile(sect.floorpicnum, sect.floorpal); + tloadtile(sect.ceilingpicnum, sect.ceilingpal); + if (sect.ceilingpicnum == LA) { tloadtile(LA + 1); tloadtile(LA + 2); } - DukeSectIterator it(i); + DukeSectIterator it(§); while (auto j = it.Next()) { if (j->s->xrepeat != 0 && j->s->yrepeat != 0 && (j->s->cstat & 32768) == 0) @@ -510,4 +508,4 @@ void prelevel_d(int g) } } -END_DUKE_NS \ No newline at end of file +END_DUKE_NS diff --git a/source/games/duke/src/premap_r.cpp b/source/games/duke/src/premap_r.cpp index b9c7a256f..a01e44ef5 100644 --- a/source/games/duke/src/premap_r.cpp +++ b/source/games/duke/src/premap_r.cpp @@ -377,29 +377,27 @@ static void cachegoodsprites(void) void cacheit_r(void) { if (!r_precache) return; - int i; cachegoodsprites(); - for(i=0;i= 0) - tloadtile(wall[i].overpicnum, wall[i].pal); + tloadtile(wal.picnum, wal.pal); + if(wal.overpicnum >= 0) + tloadtile(wal.overpicnum, wal.pal); } - for (i = 0; i < numsectors; i++) + for (auto& sect : sectors()) { - auto sectp = §or[i]; - tloadtile(sectp->floorpicnum, sectp->floorpal); - tloadtile(sectp->ceilingpicnum, sectp->ceilingpal); - if (sectp->ceilingpicnum == LA) + tloadtile(sect.floorpicnum, sect.floorpal); + tloadtile(sect.ceilingpicnum, sect.ceilingpal); + if (sect.ceilingpicnum == LA) { tloadtile(LA + 1); tloadtile(LA + 2); } - DukeSectIterator it(i); + DukeSectIterator it(§); while (auto j = it.Next()) { if(j->s->xrepeat != 0 && j->s->yrepeat != 0 && (j->s->cstat&32768) == 0)