Skip to content

Commit

Permalink
- no more picnum in spawn CCMD
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Mar 27, 2023
1 parent eb17381 commit 6000997
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
6 changes: 3 additions & 3 deletions source/common/textures/textureid.h
Expand Up @@ -45,21 +45,21 @@ class FTextureID
bool operator > (FTextureID other) const { return texnum > other.texnum; }

protected:
FTextureID(int num) { texnum = num; }
constexpr FTextureID(int num) : texnum(num) { }
private:
int texnum;
};

class FNullTextureID : public FTextureID
{
public:
FNullTextureID() : FTextureID(0) {}
constexpr FNullTextureID() : FTextureID(0) {}
};

// This is for the script interface which needs to do casts from int to texture.
class FSetTextureID : public FTextureID
{
public:
FSetTextureID(int v) : FTextureID(v) {}
constexpr FSetTextureID(int v) : FTextureID(v) {}
};

9 changes: 6 additions & 3 deletions source/games/duke/src/animatesprites_d.cpp
Expand Up @@ -180,10 +180,13 @@ void animatesprites_d(tspriteArray& tsprites, const DVector2& viewVec, DAngle vi

if (!h->GetOwner())
{
applyRotation1(h, t, viewang);
FTextureID base = FNullTextureID();
if (t->sectp->lotag == ST_2_UNDERWATER) base = TexMan.CheckForTexture("APLAYERSWIMMING", ETextureType::Any);
else if ((h->floorz - h->spr.pos.Z) > 64) base = TexMan.CheckForTexture("APLAYERJUMP", ETextureType::Any);
if (!base.isValid()) base = h->spr.spritetexture();

applyRotation1(h, t, viewang, base);

if (t->sectp->lotag == ST_2_UNDERWATER) t->picnum += DTILE_APLAYERSWIMMING - DTILE_APLAYER;
else if ((h->floorz - h->spr.pos.Z) > 64) t->picnum += DTILE_APLAYERJUMP - DTILE_APLAYER;

t->pal = ps[p].palookup;
continue;
Expand Down
25 changes: 13 additions & 12 deletions source/games/duke/src/ccmds.cpp
Expand Up @@ -44,7 +44,7 @@ static int ccmd_spawn(CCmdFuncPtr parm)
{
int x = 0, y = 0, z = 0;
ESpriteFlags cstat = 0;
int picnum = 0;
PClassActor* cls = nullptr;
unsigned int pal = 0;
DAngle ang = nullAngle;
int set = 0;
Expand Down Expand Up @@ -74,32 +74,33 @@ static int ccmd_spawn(CCmdFuncPtr parm)
[[fallthrough]];
case 1: // tile number
if (isdigit((uint8_t)parm->parms[0][0])) {
picnum = (unsigned short)atol(parm->parms[0]);
cls = GetSpawnType((unsigned short)atol(parm->parms[0]));
}
else
{
picnum = tileForName(parm->parms[0]);
if (picnum < 0)
cls = PClass::FindActor(parm->parms[0]);
if (!cls)
{
picnum = getlabelvalue(parm->parms[0]);
if (picnum < 0)
int picno = tileForName(parm->parms[0]);
if (picno < 0)
{
Printf("spawn: Invalid tile label given\n");
return CCMD_OK;
picno = getlabelvalue(parm->parms[0]);
}
cls = GetSpawnType(picno);
}
}

if (picnum >= MAXTILES) {
Printf("spawn: Invalid tile number\n");
if (cls == nullptr)
{
Printf("spawn: Invalid actor type '%s'\n", parm->parms[0]);
return CCMD_OK;
}
break;
default:
return CCMD_SHOWHELP;
}

auto spawned = spawn(ps[myconnectindex].GetActor(), picnum);
auto spawned = spawn(ps[myconnectindex].GetActor(), cls);
if (spawned)
{
if (set & 1) spawned->spr.pal = (uint8_t)pal;
Expand Down Expand Up @@ -160,7 +161,7 @@ bool GameInterface::WantEscape()

int registerosdcommands(void)
{
C_RegisterFunction("spawn","spawn <picnum> [palnum] [cstat] [ang] [x y z]: spawns a sprite with the given properties",ccmd_spawn);
C_RegisterFunction("spawn","spawn <typename> [palnum] [cstat] [ang] [x y z]: spawns a sprite with the given properties",ccmd_spawn);
return 0;
}

Expand Down
10 changes: 6 additions & 4 deletions source/games/duke/src/inlines.h
Expand Up @@ -236,7 +236,7 @@ inline int angletorotation2(DAngle sprang, DAngle viewang)
}

// 4 (8) frame rotation.
inline void applyRotation1(DDukeActor* h, tspritetype* t, DAngle viewang)
inline void applyRotation1(DDukeActor* h, tspritetype* t, DAngle viewang, FTextureID base = FNullTextureID())
{
if (tilehasmodelorvoxel(h->spr.spritetexture(), h->spr.pal))
{
Expand All @@ -251,11 +251,12 @@ inline void applyRotation1(DDukeActor* h, tspritetype* t, DAngle viewang)
t->cstat |= CSTAT_SPRITE_XFLIP;
}
else t->cstat &= ~CSTAT_SPRITE_XFLIP;
t->picnum = h->spr.picnum + k;
if (base.isNull()) base = h->spr.spritetexture();
t->setspritetexture(base + k);
}

// 6 (12) frame rotation.
inline void applyRotation2(DDukeActor* h, tspritetype* t, DAngle viewang)
inline void applyRotation2(DDukeActor* h, tspritetype* t, DAngle viewang, FTextureID base = FNullTextureID())
{
if (tilehasmodelorvoxel(h->spr.spritetexture(), h->spr.pal))
{
Expand All @@ -270,7 +271,8 @@ inline void applyRotation2(DDukeActor* h, tspritetype* t, DAngle viewang)
t->cstat |= CSTAT_SPRITE_XFLIP;
}
else t->cstat &= ~CSTAT_SPRITE_XFLIP;
t->picnum = h->spr.picnum + k;
if (base.isNull()) base = h->spr.spritetexture();
t->setspritetexture(base + k);
}

inline int monsterCheatCheck(DDukeActor* self)
Expand Down

0 comments on commit 6000997

Please sign in to comment.