SMG1 to SMG2 Code Changes

From Luma's Workshop
Revision as of 01:48, 17 December 2024 by Shibboleet (talk | contribs) (Created page with "Between the game ''Super Mario Galaxy'' and ''Super Mario Galaxy 2'', a few changes were made under the hood to make things easier to work with in the codebase. This page will be listing those changes that the developers made. == NameObj == ''NameObj'' is the most basic form of an object in the game. It contains an executor index, the execution flags, and the name of the object. <pre> class NameObj { public: NameObj(const char *pName); virtual ~NameObj(); virtual...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Between the game Super Mario Galaxy and Super Mario Galaxy 2, a few changes were made under the hood to make things easier to work with in the codebase. This page will be listing those changes that the developers made.

NameObj

NameObj is the most basic form of an object in the game. It contains an executor index, the execution flags, and the name of the object.

class NameObj {
public:
  NameObj(const char *pName);

  virtual ~NameObj();
  virtual void init(const JMapInfoIter &rIter);
  virtual void initAfterPlacement();
  virtual void movement();
  virtual void draw() const;
  virtual void calcAnim();
  virtual void calcViewAndEntry();

  /* 0x4 */ const char *mName;
  /* 0x8 */ volatile u16 mFlags;
  /* 0xA */ s16 mExecutorIdx; 
};

However, Super Mario Galaxy 2 changes the base object a little. It adds a JMapLinkInfo instance to the NameObj for easier linking using the new LinkID attribute introduced in the JMap. It also introduces two new virtual functions, NameObj::startMovement and NameObj::endMovement which are called before and after a movement is executed.

class NameObj {
public:
    NameObj(const char *);

    virtual ~NameObj();
    virtual void init(const JMapInfoIter &);
    virtual void initAfterPlacement();
    virtual void movement();
    virtual void draw() const;
    virtual void calcAnim();
    virtual void calcViewAndEntry();
    virtual void startMovement();
    virtual void endMovement();

    const char* mName;          // 0x04
    vu16 mFlags;                // 0x08
    s16 mExecutorIdx;           // 0x0A
    JMapLinkInfo mLinkInfo;     // 0x0C
};

StageSwitchContainer

StageSwitchContainer is the class that controls the switches for a specific galaxy. They are very similar in both games, with a small change (mainly for code cleanliness) made to how it works.

In Super Mario Galaxy, the StageSwitchContainer class stores an array of StageSwitch::ContainerSwitch instances that contained "data" (which is the Zone ID it is contained in) and the ZoneSwitch pointer which contained the actual switch data itself.

class StageSwitchContainer : public NameObj {
public:
    struct ContainerSwitch {
        s32 mData;              // 0x0
        ZoneSwitch* mSwitch;    // 0x4
    };
    ContainerSwitch mSwitches[20];  // 0xC
    s32 mCount;                     // 0xAC
    ZoneSwitch* mGlobalSwitches;    // 0xB0
};

The developers probably realized that the zone ID here does not need to be stored in conjunction with the switch, it can just be stored inside of the switch instance. So, they added the Zone ID attribute into ZoneSwitch and made the array smaller, as well as making it a pointer array of ZoneSwitch instances.

class StageSwitchContainer : public NameObj {
public:
    ZoneSwitch* mZoneSwitches[0x10];     // 0x14
    s32 mSwitchCount;                   // 0x54
    ZoneSwitch* mParentZone;            // 0x58
};