Skip to content

Commit

Permalink
All Games: Script action functions for psprites
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Mar 2, 2019
1 parent f54c669 commit 995fe86
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 8 deletions.
8 changes: 4 additions & 4 deletions doomsday/apps/libdoomsday/include/doomsday/world/actions.h
Expand Up @@ -32,19 +32,19 @@ typedef struct actionlink_s {
extern "C" {
#endif

LIBDOOMSDAY_PUBLIC void P_GetGameActions();

LIBDOOMSDAY_PUBLIC void P_GetGameActions();
LIBDOOMSDAY_PUBLIC acfnptr_t P_GetAction(const char *name);
LIBDOOMSDAY_PUBLIC void P_SetCurrentActionState(int state);

#ifdef __cplusplus
} // extern "C"
#endif

#ifdef __cplusplus

# include <de/String>
#include <de/String>
LIBDOOMSDAY_PUBLIC acfnptr_t P_GetAction(const de::String &name);
LIBDOOMSDAY_PUBLIC void P_SetCurrentAction(const de::String &name);
LIBDOOMSDAY_PUBLIC void P_SetCurrentAction(const de::String &name);

#endif // __cplusplus

Expand Down
29 changes: 28 additions & 1 deletion doomsday/apps/libdoomsday/src/world/actions.cpp
Expand Up @@ -19,7 +19,9 @@
#include "doomsday/world/actions.h"
#include "doomsday/gameapi.h"
#include "doomsday/doomsdayapp.h"
#include "doomsday/players.h"
#include "doomsday/world/mobjthinkerdata.h"
#include "doomsday/defs/ded.h"

#include <de/DictionaryValue>
#include <de/NativePointerValue>
Expand All @@ -33,8 +35,28 @@ using namespace de;
static QMap<String, acfnptr_t> s_actions; ///< name => native function pointer.
static String s_currentAction;

static void C_DECL A_DoomsdayScript(struct mobj_s *mobj)
static void C_DECL A_DoomsdayScript(void *actor)
{
struct mobj_s *mobj = reinterpret_cast<struct mobj_s *>(actor);

// The actor can also be a player in the case of psprites.
// Look up the corresponding player.
{
auto &plrs = DoomsdayApp::players();
for (int i = 0; i < DDMAXPLAYERS; ++i)
{
// Note: It is assumed that the player data structure begins with a pointer to
// the ddplayer_t.

if (&plrs.at(i).publicData() ==
*reinterpret_cast<const ddplayer_t * const *>(actor))
{
// Refer to the player mobj instead.
mobj = plrs.at(i).publicData().mo;
}
}
}

LOG_AS("A_DoomsdayScript");
try
{
Expand Down Expand Up @@ -77,6 +99,11 @@ void P_SetCurrentAction(const String &name)
s_currentAction = name;
}

void P_SetCurrentActionState(int state)
{
P_SetCurrentAction(DED_Definitions()->states[state].gets(QStringLiteral("action")));
}

acfnptr_t P_GetAction(const String &name)
{
if (!name.isEmpty())
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/plugins/common/src/world/mobj.cpp
Expand Up @@ -417,7 +417,7 @@ static bool changeMobjState(mobj_t *mobj, statenum_t stateNum, bool doCallAction
if (shouldCallAction(mobj))
{
// Custom parameters in the action function are passed to libdoomsday this way.
P_SetCurrentAction(Defs().states[stateNum].gets(QStringLiteral("action")));
P_SetCurrentActionState(stateNum);

void (*action)(mobj_t *);
action = de::function_cast<void (*)(mobj_t *)>(st->action);
Expand Down
3 changes: 3 additions & 0 deletions doomsday/apps/plugins/doom/src/p_pspr.c
Expand Up @@ -116,6 +116,9 @@ void P_SetPsprite(player_t* player, int position, statenum_t stnum)
// Call the state action routine (modified handling).
if(state->action)
{
// Custom parameters in the action function are passed to libdoomsday this way.
P_SetCurrentActionState((int) stnum);

state->action(player, psp);
if(!psp->state)
break;
Expand Down
3 changes: 3 additions & 0 deletions doomsday/apps/plugins/doom64/src/p_pspr.c
Expand Up @@ -123,6 +123,9 @@ void P_SetPsprite(player_t *player, int position, statenum_t stnum)
// Modified handling.
if(state->action)
{
// Custom parameters in the action function are passed to libdoomsday this way.
P_SetCurrentActionState((int) stnum);

state->action(player, psp);
if(!psp->state)
break;
Expand Down
8 changes: 7 additions & 1 deletion doomsday/apps/plugins/heretic/src/p_pspr.c
Expand Up @@ -37,6 +37,8 @@
#include "p_tick.h"
#include "player.h"

#include <doomsday/world/actions.h>

#define LOWERSPEED (6)
#define RAISESPEED (6)
#define WEAPONBOTTOM (128)
Expand Down Expand Up @@ -84,7 +86,11 @@ void P_SetPsprite(player_t *player, int position, statenum_t stnum)
}

if(state->action)
{ // Call action routine.
{
// Custom parameters in the action function are passed to libdoomsday this way.
P_SetCurrentActionState((int) stnum);

// Call action routine.
state->action(player, psp);
if(!psp->state)
{
Expand Down
6 changes: 5 additions & 1 deletion doomsday/apps/plugins/hexen/src/p_pspr.c
Expand Up @@ -320,7 +320,11 @@ void P_SetPsprite(player_t *plr, int position, statenum_t stnum)
Player_NotifyPSpriteChange(plr, position);

if(state->action)
{ // Call action routine.
{
// Custom parameters in the action function are passed to libdoomsday this way.
P_SetCurrentActionState((int) stnum);

// Call action routine.
state->action(plr, psp);
if(!psp->state)
{
Expand Down

0 comments on commit 995fe86

Please sign in to comment.