From d9fee902de186344462ced2363f8f26d28209cf7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 26 Jan 2022 22:51:36 +0100 Subject: [PATCH] - setSpritesetImage export added. --- source/games/duke/src/savegame.cpp | 1 + source/games/duke/src/types.h | 2 +- source/games/duke/src/vmexports.cpp | 21 +++++++++++++++++++ wadsrc/static/zscript/games/duke/dukeactor.zs | 3 +++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/source/games/duke/src/savegame.cpp b/source/games/duke/src/savegame.cpp index 17e84c8ac..9bf7562dd 100644 --- a/source/games/duke/src/savegame.cpp +++ b/source/games/duke/src/savegame.cpp @@ -306,6 +306,7 @@ void DDukeActor::Serialize(FSerializer& arc) ("actorstayput", actorstayput) ("dispicnum", dispicnum) ("basepicnum", basepicnum) + ("spritesetindex", spritesetindex) ("timetosleep", timetosleep) ("floorz", floorz) ("ceilingz", ceilingz) diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index ee3ac3560..06e11e318 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -36,7 +36,7 @@ public: uint8_t cgg; uint8_t spriteextra; // moved here for easier maintenance. This was originally a hacked in field in the sprite structure called 'filler'. short attackertype, hitang, hitextra, movflag; - short tempang, dispicnum, basepicnum; + short tempang, dispicnum, basepicnum, spritesetindex; short timetosleep; vec2_t ovel; int floorz, ceilingz; diff --git a/source/games/duke/src/vmexports.cpp b/source/games/duke/src/vmexports.cpp index 3f2f9ea2b..e4fb8354e 100644 --- a/source/games/duke/src/vmexports.cpp +++ b/source/games/duke/src/vmexports.cpp @@ -95,6 +95,27 @@ DEFINE_FIELD(DDukeActor, temp_actor) DEFINE_FIELD(DDukeActor, seek_actor) DEFINE_FIELD(DDukeActor, flags1) DEFINE_FIELD(DDukeActor, flags2) +DEFINE_FIELD(DDukeActor, spritesetindex) + +static void setSpritesetImage(DDukeActor* self, unsigned int index) +{ + auto& spriteset = static_cast(self->GetClass())->ActorInfo()->SpriteSet; + + if (index >= spriteset.Size()) + { + ThrowAbortException(X_ARRAY_OUT_OF_BOUNDS, "Bad sprite set index %d (max. allowed is %d", index, spriteset.Size() - 1); + } + self->spritesetindex = index; + self->spr.picnum = spriteset[index]; +} + +DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, SetSpritesetImage, setSpritesetImage) +{ + PARAM_SELF_PROLOGUE(DDukeActor); + PARAM_UINT(index); + setSpritesetImage(self, index); + return 0; +} //--------------------------------------------------------------------------- // diff --git a/wadsrc/static/zscript/games/duke/dukeactor.zs b/wadsrc/static/zscript/games/duke/dukeactor.zs index 810adaa0b..8ac775504 100644 --- a/wadsrc/static/zscript/games/duke/dukeactor.zs +++ b/wadsrc/static/zscript/games/duke/dukeactor.zs @@ -22,6 +22,8 @@ class DukeActor : CoreActor native STAT_DESTRUCT = 100, STAT_BOWLING = 105, }; + + native void SetSpritesetImage(int index); native DukeActor ownerActor, hitOwnerActor; native uint8 cgg; @@ -34,6 +36,7 @@ class DukeActor : CoreActor native native int palvals; native int temp_data[6]; native private int flags1, flags2; + native readonly int16 spritesetindex; //walltype* temp_walls[2]; // SE20 + SE128 //sectortype* temp_sect, *actorstayput;