WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Generate constants for script-command maps  #289

@lhearachel

Description

@lhearachel

Problem Statement

The assembler-macros used for compilation of field, battle, and trainer AI scripting use a a magic number-sequence to translate macro inputs into the byte-code understood by the game's internal script-processing engines. These numbers are processed by the engines as indices into a respective function table. This is a bit brittle, as it's easy for a modder to create a new scripting command for any engine, create an assembler-macro for the next element in the sequence, and accidentally inject their new function at the wrong place in the respective function table.

Proposal

We should generate a set of constants for use by each class of scripting's associated assembler-macros and function-tables. To illustrate, such constants would be made use of like so:

In asm/macros/scrcmd.inc:

    .macro Noop
-   .short 0
+   .short SCRCMD_NOOP
    .endm

    .macro Dummy
-   .short 1
+   .short SCRCMD_DUMMY
    .endm

    .macro End
-   .short 2
+   .short SCRCMD_END
    .endm

    .macro WaitTime frames, countdownVarID
-   .short 3
+   .short SCRCMD_WAITTIME
    .short \frames
    .short \countdownVarID
    .endm

In src/scrcmd.c:

const ScrCmdFunc Unk_020EAC58[] = {
    [SCRCMD_NOOP] = ScrCmd_Noop,
    [SCRCMD_DUMMY] = ScrCmd_Dummy,
    [SCRCMD_END] = ScrCmd_End,
    [SCRCMD_WAIT_TIME] = ScrCmd_WaitTime,
    // ommitted for brevity
};

One clear negative to this approach is that it adds some additional boilerplate for a modder when it comes to creating a new scripting command. However, there is also a clear authoritative association between macros and function-table, allowing a user to quickly jump between the two concepts without needing to sift through potentially many scripts making use of their command.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions