MTA:Eir/functions/engineStreamingIsGCOnDemandEnabled

From Multi Theft Auto: Wiki
Revision as of 06:46, 11 December 2013 by The GTA (talk | contribs) (Created page with "__NOTOC__ This function returns whether a Streaming garbage collector run is performed to free required Streaming GC nodes for allocation...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This function returns whether a Streaming garbage collector run is performed to free required Streaming GC nodes for allocation by certain types of entities. Objects, buildings and dummies require Streaming GC nodes so the overall Streaming memory does not grow too high. They are the ones using most of the game memory.

By default, Streaming GC on demand is disabled.

Syntax

bool engineStreamingIsGCOnDemandEnabled ()

Returns

Returns true if a Streaming garbage collector run is performed on node shortage, false otherwise.

Example

Click to collapse [-]
Client

This snippet enables infinite Streaming node allocation after two seconds of node shortage.

local firstNodeShortageTime = false;
local nodeShortageDuration = 2000;

local function isNodeShortage()
    return engineGetActiveStreamingFreeSlotCount() == 0;
end

local function enableStrictlessNodeAllocation( enabled )
    engineSetInfiniteStreamingEnabled( enabled );
    engineSetStrictNodeDistributionEnabled( not enabled );
    return true;
end

addEventHandler( "onClientPreRender", root,
    function()
        local isShortage = isNodeShortage();

        if ( isShortage ) then
            local now = getTickCount();

            if not ( firstNodeShortageTime ) then
                firstNodeShortageTime = now;
            elseif ( now - firstNodeShortageTime > nodeShortageDuration ) then
                engineStrictlessNodeAllocation( true );
            end
        else
            firstNodeShortageTime = false;
        end
    end
);