Skip to content

Commit

Permalink
- DukeActor scriptification framework.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Feb 19, 2022
1 parent f1859c6 commit ab1803b
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 10 deletions.
1 change: 0 additions & 1 deletion source/games/duke/src/actors.cpp
Expand Up @@ -622,7 +622,6 @@ void movefx(void)

//---------------------------------------------------------------------------
//
// split out of movestandables
//
//---------------------------------------------------------------------------

Expand Down
6 changes: 5 additions & 1 deletion source/games/duke/src/actors_d.cpp
Expand Up @@ -1188,7 +1188,11 @@ void movestandables_d(void)
continue;
}


if (act->GetClass() != RUNTIME_CLASS(DDukeActor))
{
CallTick(act);
continue;
}
if (picnum >= CRANE && picnum <= CRANE +3)
{
movecrane(act, CRANE);
Expand Down
5 changes: 5 additions & 0 deletions source/games/duke/src/actors_r.cpp
Expand Up @@ -830,6 +830,11 @@ void movestandables_r(void)
continue;
}

if (act->GetClass() != RUNTIME_CLASS(DDukeActor))
{
CallTick(act);
continue;
}
if (picnum >= CRANE && picnum <= CRANE +3)
{
movecrane(act, CRANE);
Expand Down
5 changes: 5 additions & 0 deletions source/games/duke/src/duke3d.h
Expand Up @@ -118,5 +118,10 @@ struct Dispatcher

extern Dispatcher fi;

void CallInitialize(DDukeActor* actor);
void CallTick(DDukeActor* actor);
void CallAction(DDukeActor* actor);


END_DUKE_NS

27 changes: 27 additions & 0 deletions source/games/duke/src/game.cpp
Expand Up @@ -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
16 changes: 10 additions & 6 deletions source/games/duke/src/premap.cpp
Expand Up @@ -941,12 +941,16 @@ static TArray<DDukeActor*> spawnactors(SpawnSpriteDef& sprites)
continue;
}
auto sprt = &sprites.sprites[i];
auto actor = static_cast<DDukeActor*>(InsertActor(RUNTIME_CLASS(DDukeActor), sprt->sectp, sprt->statnum));
spawns[j++] = actor;
actor->spr = sprites.sprites[i];
if (sprites.sprext.Size()) actor->sprext = sprites.sprext[i];
else actor->sprext = {};
actor->spsmooth = {};
auto info = spawnMap.CheckKey(sprt->picnum);
auto actor = static_cast<DDukeActor*>(InsertActor(info? info->Class() : RUNTIME_CLASS(DDukeActor), sprt->sectp, sprt->statnum));
if (actor)
{
spawns[j++] = actor;
actor->spr = sprites.sprites[i];
if (sprites.sprext.Size()) actor->sprext = sprites.sprext[i];
else actor->sprext = {};
actor->spsmooth = {};
}
}
return spawns;
}
Expand Down
5 changes: 4 additions & 1 deletion source/games/duke/src/spawn.cpp
Expand Up @@ -53,7 +53,9 @@ DDukeActor* EGS(sectortype* whatsectp, int s_x, int s_y, int s_z, int s_pn, int8
{
// sector pointer must be strictly validated here or the engine will crash.
if (whatsectp == nullptr || !validSectorIndex(sectnum(whatsectp))) return nullptr;
auto act = static_cast<DDukeActor*>(::InsertActor(RUNTIME_CLASS(DDukeActor), whatsectp, s_ss));

auto info = spawnMap.CheckKey(s_pn);
auto act = static_cast<DDukeActor*>(InsertActor(info ? info->Class() : RUNTIME_CLASS(DDukeActor), whatsectp, s_ss));

if (act == nullptr) return nullptr;
SetupGameVarsForActor(act);
Expand Down Expand Up @@ -126,6 +128,7 @@ DDukeActor* EGS(sectortype* whatsectp, int s_x, int s_y, int s_z, int s_pn, int8
act->spsmooth = {};

return act;

}


Expand Down
5 changes: 5 additions & 0 deletions source/games/duke/src/spawn_d.cpp
Expand Up @@ -43,6 +43,11 @@ BEGIN_DUKE_NS

DDukeActor* spawninit_d(DDukeActor* actj, DDukeActor* act, TArray<DDukeActor*>* actors)
{
if (act->GetClass() != RUNTIME_CLASS(DDukeActor))
{
CallOnSpawn(act);
return act;
}
auto sectp = act->sector();

if (isWorldTour())
Expand Down
5 changes: 5 additions & 0 deletions source/games/duke/src/spawn_r.cpp
Expand Up @@ -37,6 +37,11 @@ BEGIN_DUKE_NS

DDukeActor* spawninit_r(DDukeActor* actj, DDukeActor* act, TArray<DDukeActor*>* actors)
{
if (act->GetClass() != RUNTIME_CLASS(DDukeActor))
{
CallInitialize(act);
return act;
}
auto sectp = act->sector();

switch (act->spr.picnum)
Expand Down
11 changes: 10 additions & 1 deletion source/games/duke/src/types.h
Expand Up @@ -120,6 +120,16 @@ class DDukeActor : public DCoreActor

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
Expand Down Expand Up @@ -335,7 +345,6 @@ struct player_struct
{
return cursector != nullptr;
}

};

struct Cycler
Expand Down
2 changes: 2 additions & 0 deletions wadsrc/static/zscript.txt
Expand Up @@ -46,6 +46,8 @@ version "4.3"
#include "zscript/games/duke/ui/screens.zs"
#include "zscript/games/duke/ui/cutscenes.zs"
#include "zscript/games/duke/ui/menu.zs"
#include "zscript/games/duke/actors/dukeactor.zs"

#include "zscript/games/blood/bloodgame.zs"
#include "zscript/games/blood/ui/menu.zs"
#include "zscript/games/blood/ui/sbar.zs"
Expand Down
16 changes: 16 additions & 0 deletions wadsrc/static/zscript/games/duke/actors/DukeActor.zs
@@ -0,0 +1,16 @@
class DukeActor : CoreActor native
{
virtual native void Initialize();
virtual native void Tick();
virtual native void RunState(); // this is the CON function.
}

class DukeCrane : DukeActor
{
override native void Initialize();
override native void Tick();
}

class DukeCranePole : DukeActor
{
}

0 comments on commit ab1803b

Please sign in to comment.