- exported a bunch of stuff we're going to need soon.

This commit is contained in:
Christoph Oelckers 2022-11-27 21:00:22 +01:00
parent f138798e26
commit 1ef61c8588
12 changed files with 335 additions and 27 deletions

View file

@ -24,4 +24,5 @@ xx(DukeGenericDestructible)
xx(spawnstate)
xx(brokenstate)
xx(breaksound)
xx(fullbright)
xx(fullbright)
xx(spawnsound)

View file

@ -323,6 +323,11 @@ void InitThingdef()
}
);
auto collstruct = NewStruct("Collision", nullptr, true);
collstruct->Size = sizeof(CollisionBase);
collstruct->Align = alignof(CollisionBase);
auto sidestruct = NewStruct("TSprite", nullptr, true);
sidestruct->Size = sizeof(tspritetype);
sidestruct->Align = alignof(tspritetype);

View file

@ -103,6 +103,8 @@ DEFINE_FIELD_X(sectortype, sectortype, floorstat)
DEFINE_FIELD_X(sectortype, sectortype, lotag)
DEFINE_FIELD_X(sectortype, sectortype, type)
DEFINE_FIELD_X(sectortype, sectortype, hitag)
DEFINE_FIELD_X(sectortype, sectortype, ceilingheinum)
DEFINE_FIELD_X(sectortype, sectortype, floorheinum)
DEFINE_FIELD_X(sectortype, sectortype, extra)
DEFINE_FIELD_X(sectortype, sectortype, ceilingshade)
DEFINE_FIELD_X(sectortype, sectortype, ceilingpal)
@ -517,30 +519,31 @@ DEFINE_ACTION_FUNCTION_NATIVE(_walltype, point2wall, wall_point2wall)
ACTION_RETURN_POINTER(self->point2Wall());
}
double wall_deltax(walltype* wal)
void wall_delta(walltype* wal, DVector2* result)
{
if (!wal) ThrowAbortException(X_READ_NIL, nullptr);
return wal->delta().X;
*result = wal->delta();
}
DEFINE_ACTION_FUNCTION_NATIVE(_walltype, deltax, wall_point2wall)
DEFINE_ACTION_FUNCTION_NATIVE(_walltype, delta, wall_delta)
{
PARAM_SELF_STRUCT_PROLOGUE(walltype);
ACTION_RETURN_FLOAT(self->delta().X);
ACTION_RETURN_VEC2(self->delta());
}
double wall_deltay(walltype* wal)
void wall_center(walltype* wal, DVector2* result)
{
if (!wal) ThrowAbortException(X_READ_NIL, nullptr);
return wal->delta().Y;
*result = wal->center();
}
DEFINE_ACTION_FUNCTION_NATIVE(_walltype, deltay, wall_point2wall)
DEFINE_ACTION_FUNCTION_NATIVE(_walltype, center, wall_center)
{
PARAM_SELF_STRUCT_PROLOGUE(walltype);
ACTION_RETURN_FLOAT(self->delta().Y);
ACTION_RETURN_VEC2(self->center());
}
double wall_length(walltype* wal)
{
if (!wal) ThrowAbortException(X_READ_NIL, nullptr);
@ -651,6 +654,7 @@ DEFINE_FIELD(DCoreActor, spritesetindex)
DEFINE_FIELD_NAMED(DCoreActor, spr.Angles.Yaw, angle)
DEFINE_FIELD(DCoreActor, vel)
DEFINE_FIELD(DCoreActor, viewzoffset)
DEFINE_FIELD(DCoreActor, opos)
void coreactor_setpos(DCoreActor* self, double x, double y, double z, int relink)
{
@ -764,3 +768,127 @@ DEFINE_ACTION_FUNCTION_NATIVE(DCoreActor, setpositionz, coreactor_setpositionz)
coreactor_setpositionz(self, x, y, z);
return 0;
}
static double deltaangleDbl(double a1, double a2)
{
return deltaangle(DAngle::fromDeg(a1), DAngle::fromDeg(a2)).Degrees();
}
DEFINE_ACTION_FUNCTION_NATIVE(DCoreActor, deltaangle, deltaangleDbl) // should this be global?
{
PARAM_PROLOGUE;
PARAM_FLOAT(a1);
PARAM_FLOAT(a2);
ACTION_RETURN_FLOAT(deltaangle(DAngle::fromDeg(a1), DAngle::fromDeg(a2)).Degrees());
}
static double absangleDbl(double a1, double a2)
{
return absangle(DAngle::fromDeg(a1), DAngle::fromDeg(a2)).Degrees();
}
DEFINE_ACTION_FUNCTION_NATIVE(DCoreActor, absangle, absangleDbl) // should this be global?
{
PARAM_PROLOGUE;
PARAM_FLOAT(a1);
PARAM_FLOAT(a2);
ACTION_RETURN_FLOAT(absangle(DAngle::fromDeg(a1), DAngle::fromDeg(a2)).Degrees());
}
DEFINE_FIELD_X(Collision, CollisionBase, type)
DEFINE_FIELD_X(Collision, CollisionBase, exbits)
walltype* collision_getwall(CollisionBase* coll)
{
if (coll->type == kHitWall) return coll->hitWall;
else return nullptr;
}
DEFINE_ACTION_FUNCTION_NATIVE(_Collision, hitwall, collision_getwall)
{
PARAM_SELF_STRUCT_PROLOGUE(CollisionBase);
ACTION_RETURN_POINTER(collision_getwall(self));
}
sectortype* collision_getsector(CollisionBase* coll)
{
if (coll->type == kHitSector) return coll->hitSector;
else return nullptr;
}
DEFINE_ACTION_FUNCTION_NATIVE(_Collision, hitsector, collision_getsector)
{
PARAM_SELF_STRUCT_PROLOGUE(CollisionBase);
ACTION_RETURN_POINTER(collision_getsector(self));
}
DCoreActor* collision_getactor(CollisionBase* coll)
{
if (coll->type == kHitSprite) return coll->hitActor;
else return nullptr;
}
DEFINE_ACTION_FUNCTION_NATIVE(_Collision, hitactor, collision_getactor)
{
PARAM_SELF_STRUCT_PROLOGUE(CollisionBase);
ACTION_RETURN_POINTER(collision_getactor(self));
}
/////
void collision_setwall(CollisionBase* coll, walltype * w)
{
coll->type = kHitWall;
coll->hitWall = w;
}
DEFINE_ACTION_FUNCTION_NATIVE(_Collision, setwall, collision_setwall)
{
PARAM_SELF_STRUCT_PROLOGUE(CollisionBase);
PARAM_POINTER(p, walltype);
collision_setwall(self, p);
return 0;
}
void collision_setsector(CollisionBase* coll, sectortype* s)
{
coll->type = kHitSector;
coll->hitSector = s;
}
DEFINE_ACTION_FUNCTION_NATIVE(_Collision, setsector, collision_setsector)
{
PARAM_SELF_STRUCT_PROLOGUE(CollisionBase);
PARAM_POINTER(p, sectortype);
collision_setsector(self, p);
return 0;
}
void collision_setactor(CollisionBase* coll, DCoreActor* a)
{
coll->type = kHitSprite;
coll->hitActor = a;
}
DEFINE_ACTION_FUNCTION_NATIVE(_Collision, setactor, collision_setactor)
{
PARAM_SELF_STRUCT_PROLOGUE(CollisionBase);
PARAM_POINTER(p, DCoreActor);
collision_setactor(self, p);
return 0;
}
void collision_setvoid(CollisionBase* coll)
{
coll->type = kHitVoid;
coll->hitActor = nullptr;
}
DEFINE_ACTION_FUNCTION_NATIVE(_Collision, setvoid, collision_setvoid)
{
PARAM_SELF_STRUCT_PROLOGUE(CollisionBase);
collision_setvoid(self);
return 0;
}

View file

@ -386,6 +386,7 @@ enum
TFLAG_BLOCKDOOR = 1 << 6,
TFLAG_OUTERSPACE = 1 << 7,
TFLAG_NOCIRCLEREFLECT = 32,
};
enum

View file

@ -307,12 +307,12 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor,
case PLAYER_LOOGIEX:
if (bSet) ps[iPlayer].loogie[lParm2].X = lValue;
else SetGameVarID(lVar2, ps[iPlayer].loogie[lParm2].X, sActor, sPlayer);
else SetGameVarID(lVar2, (int)ps[iPlayer].loogie[lParm2].X, sActor, sPlayer);
break;
case PLAYER_LOOGIEY:
if (bSet) ps[iPlayer].loogie[lParm2].Y = lValue;
else SetGameVarID(lVar2, ps[iPlayer].loogie[lParm2].Y, sActor, sPlayer);
else SetGameVarID(lVar2, (int)ps[iPlayer].loogie[lParm2].Y, sActor, sPlayer);
break;
case PLAYER_NUMLOOGS:

View file

@ -281,6 +281,7 @@ inline int angletorotation2(DAngle sprang, DAngle viewang)
return ((sprang.Buildang() + 3072 + 128 - viewang.Buildang()) & 2047) / 170;
}
// 4 (8) frame rotation.
inline void applyRotation1(DDukeActor* h, tspritetype* t, DAngle viewang)
{
if (hw_models && modelManager.CheckModel(h->spr.picnum, h->spr.pal))
@ -299,4 +300,23 @@ inline void applyRotation1(DDukeActor* h, tspritetype* t, DAngle viewang)
t->picnum = h->spr.picnum + k;
}
// 6 (12) frame rotation.
inline void applyRotation2(DDukeActor* h, tspritetype* t, DAngle viewang)
{
if (hw_models && modelManager.CheckModel(h->spr.picnum, h->spr.pal))
{
t->cstat &= ~CSTAT_SPRITE_XFLIP;
return;
}
int k = angletorotation2(t->Angles.Yaw, viewang);
if (k > 6)
{
k = 12 - k;
t->cstat |= CSTAT_SPRITE_XFLIP;
}
else t->cstat &= ~CSTAT_SPRITE_XFLIP;
t->picnum = h->spr.picnum + k;
}
END_DUKE_NS

View file

@ -191,7 +191,7 @@ struct player_struct
PalEntry pals;
// this was a global variable originally.
vec2_t loogie[64];
DVector2 loogie[64];
// weapon drawer variables and their interpolation counterparts.
int weapon_sway;

View file

@ -183,7 +183,6 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Duke, badguyID, badguypic)
}
DEFINE_GLOBAL_UNSIZED(dlevel)
DEFINE_GLOBAL(camsprite)
@ -274,6 +273,17 @@ DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, findplayer, DukeActor_findplayer)
return min(numret, 2);
}
player_struct* DukeActor_getplayer(DDukeActor* self)
{
return self->isPlayer() ? &ps[self->PlayerIndex()] : nullptr;
}
DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, getplayer, DukeActor_getplayer)
{
PARAM_SELF_PROLOGUE(DDukeActor);
ACTION_RETURN_POINTER(DukeActor_getplayer(self));
}
int DukeActor_ifhitbyweapon(DDukeActor* self)
{
return fi.ifhitbyweapon(self);
@ -306,6 +316,19 @@ DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, PlayActorSound, DukeActor_PlayActorSou
ACTION_RETURN_INT(DukeActor_PlayActorSound(self, snd, chan, flags));
}
int DukeActor_IsSoundPlaying(DDukeActor* self, int snd, int chan)
{
return S_CheckActorSoundPlaying(self, FSoundID::fromInt(snd), chan);
}
DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, CheckSoundPlaying, DukeActor_IsSoundPlaying)
{
PARAM_SELF_PROLOGUE(DDukeActor);
PARAM_INT(snd);
PARAM_INT(chan);
ACTION_RETURN_INT(DukeActor_IsSoundPlaying(self, snd, chan));
}
void DukeActor_StopSound(DDukeActor* self, int snd, int flags)
{
S_StopSound(FSoundID::fromInt(snd), self, flags);
@ -387,6 +410,22 @@ DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, movesprite, DukeActor_movesprite)
ACTION_RETURN_INT(DukeActor_movesprite(self, velx, vely, velz, clipmask));
}
int DukeActor_movesprite_ex(DDukeActor* actor, double velx, double vely, double velz, int clipmask, Collision* coll)
{
return movesprite_ex(actor, DVector3(velx, vely, velz), clipmask, *coll);
}
DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, movesprite_ex, DukeActor_movesprite_ex)
{
PARAM_SELF_PROLOGUE(DDukeActor);
PARAM_FLOAT(velx);
PARAM_FLOAT(vely);
PARAM_FLOAT(velz);
PARAM_INT(clipmask);
PARAM_POINTER(coll, Collision);
ACTION_RETURN_INT(DukeActor_movesprite_ex(self, velx, vely, velz, clipmask, coll));
}
DDukeActor* DukeActor_Spawnsprite(DDukeActor* origin, int picnum)
{
if (picnum >= 0 && picnum < MAXTILES)
@ -490,7 +529,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, ChangeStat, ChangeActorStat)
void DukeActor_detonate(DDukeActor* origin, int intname)
{
// all callers use "EXPLOSION2", so ignore the parameter for now
// all callers use "EXPLOSION2", so ignore the parameter for now. This should be fixed once EXPLOSION2 gets scriptified.
int picnum = TileFiles.tileForName("EXPLOSION2");
detonate(origin, picnum);
}
@ -546,6 +585,33 @@ DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, isplayer, duke_isplayer)
ACTION_RETURN_INT(duke_isplayer(self));
}
void DukeActor_checkhitsprite(DDukeActor* act, DDukeActor* hitter)
{
fi.checkhitsprite(act, hitter);
}
DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, checkhitsprite, DukeActor_checkhitsprite)
{
PARAM_SELF_PROLOGUE(DDukeActor);
PARAM_POINTER(h, DDukeActor);
DukeActor_checkhitsprite(self, h);
return 0;
}
int duke_spw(DDukeActor* act)
{
return tileWidth(act->spr.picnum);
}
DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, spritewidth, duke_spw)
{
PARAM_SELF_PROLOGUE(DDukeActor);
ACTION_RETURN_INT(duke_spw(self));
}
// temporary helpers to hide the fact that these flags are not part of the actor yet.
DEFINE_ACTION_FUNCTION(DDukeActor, actorflag1)
{
@ -597,8 +663,7 @@ DEFINE_FIELD_X(DukePlayer, player_struct, ohard_landing)
DEFINE_FIELD_X(DukePlayer, player_struct, psectlotag)
//DEFINE_FIELD_X(DukePlayer, player_struct, exitx)
//DEFINE_FIELD_X(DukePlayer, player_struct, exity)
//DEFINE_FIELD_X(DukePlayer, player_struct, loogiex)
//DEFINE_FIELD_X(DukePlayer, player_struct, loogiey)
DEFINE_FIELD_UNSIZED(DukePlayer, player_struct, loogie)
DEFINE_FIELD_X(DukePlayer, player_struct, numloogs)
DEFINE_FIELD_X(DukePlayer, player_struct, loogcnt)
DEFINE_FIELD_X(DukePlayer, player_struct, invdisptime)
@ -821,6 +886,18 @@ DEFINE_ACTION_FUNCTION_NATIVE(_DukePlayer, addpos, dukeplayer_addpos)
return 0;
}
void dukeplayer_centerview(player_struct* self)
{
self->sync.actions |= SB_CENTERVIEW;
}
DEFINE_ACTION_FUNCTION_NATIVE(_DukePlayer, centerview, dukeplayer_centerview)
{
PARAM_SELF_STRUCT_PROLOGUE(player_struct);
self->sync.actions |= SB_CENTERVIEW;
return 0;
}
void dukeplayer_settargetangle(player_struct* self, double a, int backup)
{
self->Angles.setYaw(DAngle::fromDeg(a), backup);
@ -846,6 +923,19 @@ DEFINE_ACTION_FUNCTION_NATIVE(_DukePlayer, angle, dukeplayer_angle)
ACTION_RETURN_FLOAT(dukeplayer_angle(self));
}
void dukeplayer_addpitch(player_struct* self, double a)
{
self->Angles.addPitch(DAngle::fromDeg(a));
}
DEFINE_ACTION_FUNCTION_NATIVE(_DukePlayer, addpitch, dukeplayer_addpitch)
{
PARAM_SELF_STRUCT_PROLOGUE(player_struct);
PARAM_FLOAT(a);
dukeplayer_addpitch(self, a);
return 0;
}
DEFINE_ACTION_FUNCTION_NATIVE(_DukePlayer, clearcameras, clearcameras)
{
PARAM_SELF_STRUCT_PROLOGUE(player_struct);
@ -1016,6 +1106,37 @@ DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, ismirror, duke_ismirror)
ACTION_RETURN_BOOL(duke_ismirror(wal));
}
void duke_checkhitwall(walltype* wal, DDukeActor * actor, double x, double y, double z)
{
fi.checkhitwall(actor, wal, DVector3(x, y, z), actor->spr.picnum);
}
DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, checkhitwall, duke_checkhitwall)
{
PARAM_PROLOGUE;
PARAM_POINTER(wal, walltype);
PARAM_POINTER(act, DDukeActor);
PARAM_FLOAT(x);
PARAM_FLOAT(y);
PARAM_FLOAT(z);
duke_checkhitwall(wal, act, x, y, z);
return 0;
}
void duke_checkhitceiling(sectortype* sect, DDukeActor* actor)
{
fi.checkhitceiling(sect); // actor is currently unused, this may change.
}
DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, checkhitceiling, duke_checkhitceiling)
{
PARAM_PROLOGUE;
PARAM_POINTER(wal, sectortype);
PARAM_POINTER(act, DDukeActor);
fi.checkhitceiling(wal);
return 0;
}
DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, addcycler, addcycler)
{
PARAM_PROLOGUE;

View file

@ -27,6 +27,7 @@ class CoreActor native
native int16 cstat;
//native int16 picnum; // access is disabled to allow later refactoring.
native Vector3 pos;
native Vector3 opos;
native readonly int16 statnum;
native int16 intangle;
native int16 xint;
@ -67,6 +68,9 @@ class CoreActor native
native void setPosition(Vector3 pos);
native void setPositionZ(Vector3 pos);
native clearscope static double deltaangle(double ang1, double ang2);
native clearscope static double absangle(double ang1, double ang2);
int randomFlip()
{
int r = random(0, 3);
@ -85,3 +89,18 @@ class CoreActor native
}
// this only allows function getters to enable validation on the target.
struct Collision
{
native int type;
native int exbits;
native walltype hitWall();
native sectortype hitSector();
native CoreActor hitActor();
native void setSector(sectortype s);
native void setWall(walltype w);
native void setActor(CoreActor a);
native void setVoid();
}

View file

@ -157,9 +157,11 @@ class DukeActor : CoreActor native
native void getglobalz();
native DukePlayer, double findplayer();
native DukePlayer GetPlayer();
native int ifhitbyweapon();
native int domove(int clipmask);
native int PlayActorSound(Sound snd, int chan = CHAN_AUTO, int flags = 0);
native int CheckSoundPlaying(Sound snd, int chan = CHAN_AUTO);
native void StopSound(Sound snd, int flags = 0);
native DukeActor spawn(Name type);
native DukeActor spawnsprite(int type); // for cases where the map has a picnum stored. Avoid when possible.
@ -169,6 +171,11 @@ class DukeActor : CoreActor native
native void detonate(name type);
native void checkhitdefault(DukeActor proj);
native void operatesectors(sectortype sec);
native int SpriteWidth();
native void checkhitsprite(DukeActor hitter);
virtual void BeginPlay() {}
virtual void StaticSetup() {}
@ -193,6 +200,7 @@ class DukeActor : CoreActor native
native void lotsofstuff(Name type, int count);
native double gutsoffset();
native int movesprite(Vector3 move, int clipmask);
native int movesprite_ex(Vector3 move, int clipmask, Collision coll);
// temporary flag accessors - need to be eliminated once we can have true actor flags
@ -200,8 +208,6 @@ class DukeActor : CoreActor native
native int actorflag2(int mask);
native int attackerflag1(int mask);
native int attackerflag2(int mask);
}
extend struct _
@ -228,6 +234,8 @@ struct DukeLevel
native static int addambient(int hitag, int lotag);
native static void resetswitch(int tag); //
native bool isMirror(walltype wal);
native void checkhitwall(walltype wal, DukeActor hitter, Vector3 hitpos);
native void checkhitceiling(sectortype wal, DukeActor hitter);
}
struct DukeStatIterator

View file

@ -75,6 +75,7 @@ struct Duke native
TFLAG_ELECTRIC = 4,
TFLAG_CLEARINVENTORY = 8, // really dumb Duke stuff...
TFLAG_SLIME = 16,
TFLAG_NOCIRCLEREFLECT = 32,
};
enum ESoundFlags
@ -100,6 +101,10 @@ struct Duke native
native static int global_random();
native static int GetSoundFlags(Sound snd);
native static int badguyID(int id);
static int rnd(int val)
{
return (random(0, 255) >= (255 - (val)));
}
static void PlayBonusMusic()
{
@ -173,7 +178,7 @@ struct DukePlayer native
// Store current psectlotag as determined in processinput() for use with scaling angle aiming.
native int16 psectlotag;
// From here on it is unaltered from JFDuke with the exception of a few fields that are no longer needed and were removed.
native Vector2 loogie[64];
native int numloogs, loogcnt;
native int invdisptime;
native double pyoff, opyoff;
@ -293,6 +298,8 @@ struct DukePlayer native
native double angle();
native void clearcameras();
native void quickkill();
native void addPitch(double p);
native void centerView();
}

View file

@ -97,6 +97,8 @@ enum ETSprFlags
TSPR_FLAGS_DRAW_LAST = 2, // Currently unused: checked by Polymost but never set.
TSPR_MDLROTATE = 4, // rotate if this is a model or voxel.
TSPR_SLOPESPRITE = 8, // render as sloped sprite
TSPR_ROTATE8FRAMES = 16, // do an 8 frame rotation
TSPR_ROTATE12FRAMES = 32, // do an 12 frame rotation
}
enum ESectorExBits
@ -122,12 +124,12 @@ struct sectortype native
native readonly float floorxpan;
native readonly float floorypan;
native readonly double ceilingz, floorz;
native readonly int16 ceilingheinum;
native readonly int16 floorheinum;
native Array<@walltype> walls;
native int16 ceilingstat;
native int16 floorstat;
//int16 ceilingpicnum;
//int16 floorpicnum;
native int16 lotag;
native int16 type; // type is an alias of lotag for Blood.
@ -262,12 +264,8 @@ struct walltype native
native walltype nextWallp() const;
native walltype lastWall() const;
native walltype point2Wall() const;
/*
Vector2 delta() const;
Vector2 center() const;
*/
native double deltax() const;
native double deltay() const;
native Vector2 delta() const;
native Vector2 center() const;
native bool twoSided() const;
native double Length();