BF2 Internals

From BF2 Technical Information Wiki
Jump to navigation Jump to search

The BF2 engine has been written in C++ and also make heavy use of STL.

Reference Counting

A lot of the internal components of the game use intrusive reference counting through inheritance. The base class would look something like this:

class RefCounted {
public:
    RefCounted() : m_refCount(1) {}
    virtual ~RefCounted() {}

    virtual int addRef() {
        return ++m_refCount;
    }
    
    virtual int getRefCount() const {
        return m_refCount;
    }

    virtual int release() {
        if (--m_refCount == 0) {
            delete (RefCounted*)this;
        }
        return m_refCount;
    }
private:
    int m_refCount;
}

Do note that this class is not thread-safe, as in the actual implementation.

ClassManager

The program contains a single ClassManager instance which is used to dynamically access different subsystems within the game. These subsystems are registered via a string identifier(class name), an instance pointer, the class id and another unknown integer, they can then later be accessed using the class name. The following classes are registered in BF2.exe:

GameServerSettings
HudInformationLayer
DistributedLightRenderer
LocalProfileManager
ProfileManager
RankManager
ClanManager
NewsManager
AutoPatch
Persistence
MenuTeamManager
GlobalSettings
VideoSettings
AudioSettings
ControlSettings
GeneralSettings
HapticSettings
ServerBrowserManager
SwiffHost
DemoLibrary
ServerLogoManager
ModInfo

The rendering module(RendDX9.dll) also registers the following classes:

SwiffRenderer
Terrain
LightManager
GeometryTemplateManager
StaticMeshRenderer
SkinnedMeshRenderer
ParticleSystemManager
HemiMapManager
DecalManager
DecalShadowManager
RoadCompiledRenderer
RoadEditableRenderer
NametagManager
SkyDome
UndergrowthSystem
LightingManager
WeatherManager
RainManager
RenderView
EnvMapManager