Game Development Reference
In-Depth Information
if (!pCastEventData->GetUiString().empty())
m_gameplayText = s2ws(pCastEventData->GetUiString());
else
m_gameplayText.clear();
}
This event delegate is pretty simple: It just casts the event to the proper type and
reads it from the event. The s2ws() function converts the ASCII string into a
std::wstring , which is then stored in a member variable. During the next render
pass, this string is rendered to the top-middle portion of the screen.
This is great for sending events, but what about receiving them? It is often useful to
have all of the event listeners in one place since most event listeners just call into
another system. Teapot Wars has an Events.lua file for just that purpose:
function OnPhysicsCollision(eventData)
g_actorMgr:OnPhysicsCollision(eventData);
end
function OnFireWeapon(eventData)
g_actorMgr:OnFireWeapon(eventData);
end
function RegisterListeners()
if (EventType.EvtData_PhysCollision
= nil) then
RegisterEventListener(EventType.EvtData_PhysCollision,
OnPhysicsCollision);
˜
end
= nil) then
RegisterEventListener(EventType.EvtData_Fire_Weapon, OnFireWeapon);
end
end
if (EventType.EvtData_Fire_Weapon
˜
This file declares three functions. The first two are event listener delegates, and the
third is called to register those listeners. Let
s say a collision is registered by the phys-
ics system in C++. This will trigger the EvtData_PhysCollision event, which will
be handled by OnPhysicsCollision() . That function calls into the actor manager.
'
function ActorManager:OnPhysicsCollision(eventData)
local actorA = self:GetActorById(eventData.actorA);
local actorB = self:GetActorById(eventData.actorB);
-- one of the actors isn
t in the script manager
if (actorA == nil or actorB == nil) then
'
Search WWH ::




Custom Search