TF2-DMB / CBaseNPC

Provides a friendly interface for plugins to use in order to create custom NPCs on the game Team Fortress 2
36 stars 5 forks source link

Revise natives code #40

Closed Kenzzer closed 1 year ago

Kenzzer commented 1 year ago

What's changed ?

Instead of all the natives being inside various include files, and then all included by natives.h we instead divide those natives into multiple .hpp and .cpp files, available in the natives directory. Very much mirroring the setup of our .inc files.

New way to register natives

No more global array, instead an std::vector is passed around by reference. The natives are then added to it by each .cpp module. Furthermore, macros to define native functions have been eliminated. Everything are now locally defined functions, only available in their respective .cpp file.

Example :

void setup(std::vector<sp_nativeinfo_t>& natives) {
    area::setup(natives);
    surroundingareas::setup(natives);

    tf::nav::setup(natives);

    sp_nativeinfo_t list[] = {
        {"CNavMesh.Address.get", GetAddress},
        {"CNavMesh.IsLoaded", IsLoaded},
        {"CNavMesh.IsAnalyzed", IsAnalyzed},
        {"CNavMesh.IsOutOfDate", IsOutOfDate},
        {"CNavMesh.GetNavAreaCount", GetNavAreaCount},
        {"CNavMesh.CollectSurroundingAreas", CollectSurroundingAreas},
        {"CNavMesh.GetNavAreaByID", GetNavAreaByID},
        {"CNavMesh.GetNearestNavArea", GetNearestNavArea},
        {"CNavMesh.BuildPath", BuildPath},
        {"CNavMesh.GetNavArea", GetNavArea},
        {"CNavMesh.GetNavAreaEntity", GetNavAreaEntity},
    };

    natives.insert(natives.end(), std::begin(list), std::end(list));
}

New coding style for {}

As of this PR, I wish that we adopt Rust's styling for .cpp and .hpp files. The extension never had a coding style to begin with, so I believe this is a good point to start introducing some.

New/updated natives

Prepare for TF2 x64 bits

In addition to everything above, speculative but correct changes have been made to hopefully prepare enough the extension for the eventual release of 64bits tf2. See alliedmodders/hl2sdk#127 for further details.