From 789794539c047c5f05f398b489e5038d1129df70 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 21 Feb 2022 00:19:26 +0100 Subject: [PATCH] - added script exports for Duke's main structures. --- source/games/duke/src/duke3d.h | 5 + source/games/duke/src/game.cpp | 27 +++++ source/games/duke/src/types.h | 11 +- source/games/duke/src/vmexports.cpp | 109 ++++++++++++++++++ source/games/duke/src/vmiterators.cpp | 6 +- wadsrc/static/zscript/games/duke/dukeactor.zs | 16 ++- wadsrc/static/zscript/games/duke/dukegame.zs | 14 ++- 7 files changed, 177 insertions(+), 11 deletions(-) diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index 5e25d586b..8bbcd6017 100644 --- a/source/games/duke/src/duke3d.h +++ b/source/games/duke/src/duke3d.h @@ -118,5 +118,10 @@ struct Dispatcher extern Dispatcher fi; +void CallInitialize(DDukeActor* actor); +void CallTick(DDukeActor* actor); +void CallAction(DDukeActor* actor); + + END_DUKE_NS diff --git a/source/games/duke/src/game.cpp b/source/games/duke/src/game.cpp index e5d22799e..14a15145e 100644 --- a/source/games/duke/src/game.cpp +++ b/source/games/duke/src/game.cpp @@ -400,4 +400,31 @@ void GameInterface::app_init() } +void CallInitialize(DDukeActor* actor) +{ + IFVIRTUALPTR(actor, DDukeActor, initialize) + { + VMValue val = actor; + VMCall(func, &val, 1, nullptr, 0); + } +} + +void CallTick(DDukeActor* actor) +{ + IFVIRTUALPTR(actor, DDukeActor, Tick) + { + VMValue val = actor; + VMCall(func, &val, 1, nullptr, 0); + } +} + +void CallAction(DDukeActor* actor) +{ + IFVIRTUALPTR(actor, DDukeActor, RunState) + { + VMValue val = actor; + VMCall(func, &val, 1, nullptr, 0); + } +} + END_DUKE_NS diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index 7ae1be049..d2a40da9f 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -120,6 +120,16 @@ public: void Serialize(FSerializer& arc) override; + void ChangeType(PClass* newtype) + { + if (newtype->IsDescendantOf(RUNTIME_CLASS(DDukeActor)) && newtype->Size == RUNTIME_CLASS(DDukeActor)->Size && GetClass()->Size == RUNTIME_CLASS(DDukeActor)->Size) + { + // It sucks having to do this but the game heavily depends on being able to swap out the class type and often uses this to manage actor state. + // We'll allow this only for classes that do not add their own data, though. + SetClass(newtype); + } + } + }; // subclassed to add a game specific actor() method @@ -335,7 +345,6 @@ struct player_struct { return cursector != nullptr; } - }; struct Cycler diff --git a/source/games/duke/src/vmexports.cpp b/source/games/duke/src/vmexports.cpp index e4fb8354e..53d8327eb 100644 --- a/source/games/duke/src/vmexports.cpp +++ b/source/games/duke/src/vmexports.cpp @@ -69,6 +69,20 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Duke, CheckSoundPlaying, S_CheckSoundPlaying) ACTION_RETURN_INT(S_CheckSoundPlaying(snd)); } +player_struct* duke_checkcursectnums(sectortype* sector) +{ + if (!sector) return nullptr; + int pp = checkcursectnums(sector); + return pp ? &ps[pp] : nullptr; +} + +DEFINE_ACTION_FUNCTION_NATIVE(_Duke, checkcursectnums, duke_checkcursectnums) +{ + PARAM_PROLOGUE; + PARAM_POINTER(sect, sectortype); + ACTION_RETURN_POINTER(duke_checkcursectnums(sect)); +} + DEFINE_GLOBAL_UNSIZED(dlevel) //--------------------------------------------------------------------------- @@ -96,6 +110,9 @@ DEFINE_FIELD(DDukeActor, seek_actor) DEFINE_FIELD(DDukeActor, flags1) DEFINE_FIELD(DDukeActor, flags2) DEFINE_FIELD(DDukeActor, spritesetindex) +DEFINE_FIELD(DDukeActor, temp_walls) +DEFINE_FIELD(DDukeActor, temp_sect) +DEFINE_FIELD(DDukeActor, actorstayput) static void setSpritesetImage(DDukeActor* self, unsigned int index) { @@ -117,6 +134,56 @@ DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, SetSpritesetImage, setSpritesetImage) return 0; } +DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, getglobalz, getglobalz) +{ + PARAM_SELF_PROLOGUE(DDukeActor); + getglobalz(self); + return 0; +} + +player_struct* DukeActor_findplayer(DDukeActor* self) +{ + int a; + return &ps[findplayer(self, &a)]; +} + +DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, findplayer, DukeActor_findplayer) +{ + PARAM_SELF_PROLOGUE(DDukeActor); + ACTION_RETURN_POINTER(DukeActor_findplayer(self)); +} + +int DukeActor_ifhitbyweapon(DDukeActor* self) +{ + return fi.ifhitbyweapon(self); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, ifhitbyweapon, DukeActor_ifhitbyweapon) +{ + PARAM_SELF_PROLOGUE(DDukeActor); + ACTION_RETURN_INT(DukeActor_ifhitbyweapon(self)); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, domove, ssp) +{ + PARAM_SELF_PROLOGUE(DDukeActor); + PARAM_INT(clipmask); + ACTION_RETURN_INT(ssp(self, clipmask)); +} + +int DukeActor_PlayActorSound(DDukeActor* self, int snd) +{ + return S_PlayActorSound(snd, self); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, PlayActorSound, DukeActor_PlayActorSound) +{ + PARAM_SELF_PROLOGUE(DDukeActor); + PARAM_INT(snd); + ACTION_RETURN_INT(DukeActor_PlayActorSound(self, snd)); +} + + //--------------------------------------------------------------------------- // // DukePlayer @@ -288,6 +355,13 @@ DEFINE_FIELD_X(DukePlayer, player_struct, vehTurnLeft) DEFINE_FIELD_X(DukePlayer, player_struct, vehTurnRight) DEFINE_FIELD_X(DukePlayer, player_struct, vehBraking) DEFINE_FIELD_X(DukePlayer, player_struct, holoduke_on) +DEFINE_FIELD_X(DukePlayer, player_struct, actorsqu) +DEFINE_FIELD_X(DukePlayer, player_struct, wackedbyactor) +DEFINE_FIELD_X(DukePlayer, player_struct, on_crane) +DEFINE_FIELD_X(DukePlayer, player_struct, somethingonplayer) +DEFINE_FIELD_X(DukePlayer, player_struct, access_spritenum) +DEFINE_FIELD_X(DukePlayer, player_struct, dummyplayersprite) +DEFINE_FIELD_X(DukePlayer, player_struct, newOwner) DEFINE_ACTION_FUNCTION(_DukePlayer, IsFrozen) { @@ -303,6 +377,41 @@ DEFINE_ACTION_FUNCTION(_DukePlayer, GetGameVar) ACTION_RETURN_INT(GetGameVar(name, def, self->GetActor(), self->GetPlayerNum()).safeValue()); } +DEFINE_ACTION_FUNCTION(_DukePlayer, angleAsBuild) +{ + PARAM_SELF_STRUCT_PROLOGUE(player_struct); + ACTION_RETURN_INT(self->angle.ang.asbuild()); +} + +void dukeplayer_backuppos(player_struct* self) +{ + self->backuppos(); +} + +DEFINE_ACTION_FUNCTION_NATIVE(_DukePlayer, backuppos, dukeplayer_backuppos) +{ + PARAM_SELF_STRUCT_PROLOGUE(player_struct); + dukeplayer_backuppos(self); + return 0; +} + +void dukeplayer_setpos(player_struct* self, double x, double y, double z) +{ + self->pos.X = int(x * worldtoint); + self->pos.Y = int(y * worldtoint); + self->pos.Z = int(z * zworldtoint); +} + +DEFINE_ACTION_FUNCTION_NATIVE(_DukePlayer, setpos, dukeplayer_setpos) +{ + PARAM_SELF_STRUCT_PROLOGUE(player_struct); + PARAM_FLOAT(x); + PARAM_FLOAT(y); + PARAM_FLOAT(z); + dukeplayer_setpos(self, x, y, z); + return 0; +} + //--------------------------------------------------------------------------- // diff --git a/source/games/duke/src/vmiterators.cpp b/source/games/duke/src/vmiterators.cpp index 3a696fa2e..43ceeb1c5 100644 --- a/source/games/duke/src/vmiterators.cpp +++ b/source/games/duke/src/vmiterators.cpp @@ -98,7 +98,7 @@ public: DukeSectIterator it; - DDukeSectIterator(int Sectnum) + DDukeSectIterator(sectortype* Sectnum) : it(Sectnum) { } @@ -106,7 +106,7 @@ public: IMPLEMENT_CLASS(DDukeSectIterator, true, false); -static DDukeSectIterator *CreateSectIterator(int Sectnum) +static DDukeSectIterator *CreateSectIterator(sectortype* Sectnum) { return Create(Sectnum); } @@ -114,7 +114,7 @@ static DDukeSectIterator *CreateSectIterator(int Sectnum) DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, CreateSectorIterator, CreateSectIterator) { PARAM_PROLOGUE; - PARAM_INT(Sectnum); + PARAM_POINTER(Sectnum, sectortype); ACTION_RETURN_OBJECT(CreateSectIterator(Sectnum)); } diff --git a/wadsrc/static/zscript/games/duke/dukeactor.zs b/wadsrc/static/zscript/games/duke/dukeactor.zs index 8ac775504..fd09cb7f7 100644 --- a/wadsrc/static/zscript/games/duke/dukeactor.zs +++ b/wadsrc/static/zscript/games/duke/dukeactor.zs @@ -37,8 +37,8 @@ class DukeActor : CoreActor native native int temp_data[6]; native private int flags1, flags2; native readonly int16 spritesetindex; - //walltype* temp_walls[2]; // SE20 + SE128 - //sectortype* temp_sect, *actorstayput; + native walltype temp_walls[2]; + native sectortype temp_sect, actorstayput; native DukeActor temp_actor, seek_actor; @@ -65,10 +65,16 @@ class DukeActor : CoreActor native flagdef SE24_NoFloorCheck: flags1, 19; flagdef NoInterpolate: flags1, 20; + native void getglobalz(); + native DukePlayer findplayer(); + native int ifhitbyweapon(); + native int domove(int clipmask); + native void PlayActorSound(int snd); virtual void BeginPlay() {} - virtual bool Tick() { return false; } - + virtual void Initialize() {} + virtual void Tick() {} + virtual void RunState() {} // this is the CON function. } extend struct _ @@ -81,7 +87,7 @@ extend struct _ struct DukeLevel { native static DukeStatIterator CreateStatIterator(int stat); - native static DukeSectIterator CreateSectorIterator(int sect); + native static DukeSectIterator CreateSectorIterator(sectortype sect); native static DukeSpriteIterator CreateSpriteIterator(); } diff --git a/wadsrc/static/zscript/games/duke/dukegame.zs b/wadsrc/static/zscript/games/duke/dukegame.zs index 6577f6e18..381433138 100644 --- a/wadsrc/static/zscript/games/duke/dukegame.zs +++ b/wadsrc/static/zscript/games/duke/dukegame.zs @@ -61,6 +61,12 @@ struct Duke native ICON_BOOTS, ICON_MAX }; + + enum EClipMask + { + CLIPMASK0 = (1 << 16) + 1, + CLIPMASK1 = (256 << 16) + 64 + } native static void PlaySpecialMusic(int which); native static int PlaySound(int num, int channel = CHAN_AUTO, int flags = 0, float vol =0.8f); @@ -69,6 +75,7 @@ struct Duke native native static DukePlayer GetViewPlayer(); native static int MaxPlayerHealth(); native static int MaxAmmoAmount(int weap); + native static DukePlayer checkcursectnums(sectortype sect); static void PlayBonusMusic() { @@ -174,8 +181,8 @@ struct DukePlayer native int16 cheat_phase; native int16 extra_extra8, quick_kick, last_quick_kick; native int16 heat_amount, timebeforeexit, customexitsound; - //DDukeActor* actor, actorsqu, *wackedbyactor, *on_crane, *holoduke_on, *somethingonplayer, *access_spritenum, *dummyplayersprite, *newOwner; // later - native voidptr holoduke_on; // cannot do it as a proper actor pointer yet - but the status bar needs it. + native DukeActor actor, actorsqu, wackedbyactor, on_crane, somethingonplayer, access_spritenum, dummyplayersprite, newOwner, holoduke_on; + native sectortype cursector; native int16 weaprecs[256], weapreccnt; native uint interface_toggle_flag; @@ -260,6 +267,9 @@ struct DukePlayer native bool IsFrozen(); native int GetGameVar(String varname, int defval); + native int angleAsBuild(); + native void backuppos(); + native void setpos(Vector3 pos); }