Reader small image

You're reading from  Learning Game AI Programming with Lua

Product typeBook
Published inNov 2014
Reading LevelBeginner
PublisherPackt
ISBN-139781783281336
Edition1st Edition
Languages
Right arrow
Author (1)
David Young
David Young
Right arrow

Handling new agent sightings


As visibility can be updated very often, we only want to send out events for new agent sightings. We can create a helper function that will take a list of known agents indexed by their agent ID numbers and a list of currently visible agents. By storing the lastSeen time of a sighting, we can determine whether an event should be sent out.

Throttling events in this fashion prevents an abundance of redundant events from being propagated. As events are sent to every registered object, this can have an impact on performance when massive amounts of events are being sent:

AgentSenses.lua:

local function HandleNewAgentSightings(
    userData, knownAgents, spottedAgents)
    
    local newAgentSightings = {};
    
    for key, value in pairs(spottedAgents) do
        local agentId = value.agent:GetId();
        local lastSeen =
            value.lastSeen - knownAgents[agentId].lastSeen;
    
        if (knownAgents[agentId] == nil or lastSeen > 500) then
           ...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Learning Game AI Programming with Lua
Published in: Nov 2014Publisher: PacktISBN-13: 9781783281336

Author (1)