- got rid of setspritez(x) and moved the implementation to SetActor(Z) without referencing the sprite array.

This commit is contained in:
Christoph Oelckers 2021-12-03 20:20:33 +01:00
parent 6773fa2189
commit 2654a19cfd
5 changed files with 35 additions and 57 deletions

View file

@ -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)));

View file

@ -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);

View file

@ -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;

View file

@ -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);
}

View file

@ -99,14 +99,14 @@ 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;
}