From 2654a19cfd1633ff846ca8c326b8d75fa1a7cee8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 3 Dec 2021 20:20:33 +0100 Subject: [PATCH] - got rid of setspritez(x) and moved the implementation to SetActor(Z) without referencing the sprite array. --- source/build/include/build.h | 6 --- source/build/include/buildtypes.h | 5 +++ source/build/src/engine.cpp | 61 ++++++++++++------------------- source/core/coreactor.h | 14 ++----- source/games/duke/src/ccmds.cpp | 6 +-- 5 files changed, 35 insertions(+), 57 deletions(-) diff --git a/source/build/include/build.h b/source/build/include/build.h index 0b777d84c..317b5f2e8 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -523,12 +523,6 @@ int32_t deletesprite(int16_t spritenum); int32_t changespritesect(int16_t spritenum, int16_t newsectnum); int32_t changespritestat(int16_t spritenum, int16_t newstatnum); -int32_t setsprite(int16_t spritenum, const vec3_t *) ATTRIBUTE((nonnull(2))); -inline int32_t setsprite(int16_t spritenum, int x, int y, int z) -{ - vec3_t v = { x,y,z }; - return setsprite(spritenum, &v); -} int32_t setspritez(int16_t spritenum, const vec3_t *) ATTRIBUTE((nonnull(2))); diff --git a/source/build/include/buildtypes.h b/source/build/include/buildtypes.h index 5889386bd..24e13b915 100644 --- a/source/build/include/buildtypes.h +++ b/source/build/include/buildtypes.h @@ -410,6 +410,11 @@ struct spritetype backupang(); } + void setpos(const vec3_t& newpos) + { + pos = newpos; + } + int32_t interpolatedx(double const smoothratio, int const scale = 16) { return interpolatedvalue(ox, x, smoothratio, scale); diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 469ee0893..0b445764e 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -31,6 +31,7 @@ #include "render.h" #include "gamefuncs.h" #include "hw_voxels.h" +#include "coreactor.h" #ifdef USE_OPENGL # include "mdsprite.h" @@ -764,44 +765,6 @@ int32_t spriteheightofsptr(uspriteptr_t spr, int32_t *height, int32_t alsotileyo return zofs; } -// -// setsprite -// -int32_t setsprite(int16_t spritenum, const vec3_t *newpos) -{ - auto tempsector = sprite[spritenum].sector(); - - if (newpos != &sprite[spritenum].pos) - sprite[spritenum].pos = *newpos; - - updatesector(newpos->x,newpos->y,&tempsector); - - if (tempsector == nullptr) - return -1; - if (tempsector != sprite[spritenum].sector()) - changespritesect(spritenum, sectnum(tempsector)); - - return 0; -} - -int32_t setspritez(int16_t spritenum, const vec3_t *newpos) -{ - auto tempsectnum = sprite[spritenum].sector(); - - if ((void const *)newpos != (void *)&sprite[spritenum]) - sprite[spritenum].pos = *newpos; - - updatesectorz(newpos->x,newpos->y,newpos->z,&tempsectnum); - - if (tempsectnum == nullptr) - return -1; - if (tempsectnum != sprite[spritenum].sector()) - changespritesect(spritenum, sectnum(tempsectnum)); - - return 0; -} - - // // nextsectorneighborz // @@ -1444,6 +1407,28 @@ int tilehasmodelorvoxel(int const tilenume, int pal) } +void SetActor(DCoreActor* actor, const vec3_t* newpos) +{ + auto tempsector = actor->sector(); + actor->s().setpos(*newpos); + updatesector(newpos->x, newpos->y, &tempsector); + + if (tempsector && tempsector != actor->sector()) + ChangeActorSect(actor, tempsector); +} + +void SetActorZ(DCoreActor* actor, const vec3_t* newpos) +{ + auto tempsector = actor->sector(); + actor->s().setpos(*newpos); + updatesectorz(newpos->x, newpos->y, newpos->z, &tempsector); + + if (tempsector && tempsector != actor->sector()) + ChangeActorSect(actor, tempsector); +} + + + CCMD(updatesectordebug) { int sect = 319; diff --git a/source/core/coreactor.h b/source/core/coreactor.h index 9571cec0a..37826d7dd 100644 --- a/source/core/coreactor.h +++ b/source/core/coreactor.h @@ -301,19 +301,13 @@ inline void ChangeActorSect(DCoreActor* actor, sectortype* sect) changespritesect(actor->GetSpriteIndex(), sector.IndexOf(sect)); } -inline int SetActorZ(DCoreActor* actor, const vec3_t* newpos) -{ - return setspritez(actor->GetSpriteIndex(), newpos); -} -inline int SetActor(DCoreActor* actor, const vec3_t* newpos) -{ - return setsprite(actor->GetSpriteIndex(), newpos); -} +void SetActorZ(DCoreActor* actor, const vec3_t* newpos); +void SetActor(DCoreActor* actor, const vec3_t* newpos); -inline int SetActor(DCoreActor* actor, const vec3_t& newpos) +inline void SetActor(DCoreActor* actor, const vec3_t& newpos) { - return setsprite(actor->GetSpriteIndex(), &newpos); + SetActor(actor, &newpos); } diff --git a/source/games/duke/src/ccmds.cpp b/source/games/duke/src/ccmds.cpp index c2a1f96f2..5f3b731a2 100644 --- a/source/games/duke/src/ccmds.cpp +++ b/source/games/duke/src/ccmds.cpp @@ -99,13 +99,13 @@ static int ccmd_spawn(CCmdFuncPtr parm) if (set & 1) spawned->s->pal = (uint8_t)pal; if (set & 2) spawned->s->cstat = (uint16_t)cstat; if (set & 4) spawned->s->ang = ang; - if (set & 8) { - if (SetActor(spawned, { x, y, z }) < 0) + if (set & 8) + SetActor(spawned, { x, y, z }); + if (spawned->sector() == nullptr) { Printf("spawn: Sprite can't be spawned into null space\n"); deletesprite(spawned); } - } } return CCMD_OK;