Game Development Reference
In-Depth Information
}
}
}
The first thing this function does is to call the base class version. This is extremely
important because there is a lot of important processing that happens there.
If the BGS_WaitingForPlayers state is the state being transitioned to, the code
spawns all the local players, unless this is a proxy. If this is a proxy, there is very little
to do except attach a view. Otherwise, the appropriate type of view is created for that
type of player and added to the list of views the game logic maintains. These views
are often game-specific views tied directly to that game.
The BGS_SpawningPlayersActors state signals that it
s time to spawn all the
actors into the world. It loops through all the game views and creates the appropriate
type of actor. It also sends the EvtData_New_Actor event to let other systems
know that an actor has been created.
Let ' s take a look at a few examples of how the engine handles some of the events sent
from the game layer. In the Scene class (which you saw in Chapter 16,
'
3D Scenes
),
there are two delegates that respond to the creation and destruction of actors. Here
'
s
the one for new actors:
void Scene::NewRenderComponentDelegate(IEventDataPtr pEventData)
{
shared_ptr<EvtData_New_Render_Component> pCastEventData =
static_pointer_cast<EvtData_New_Render_Component>(pEventData);
ActorId actorId = pCastEventData->GetActorId();
shared_ptr<SceneNode> pSceneNode(pCastEventData->GetSceneNode());
//TODO: Add real error handling here.
if (FAILED(pSceneNode->VOnRestore(this)))
{
GCC_ERROR(“Failed to add scene node to the scene for actorid ” +
ToStr(actorId));
return;
}
AddChild(actorId, pSceneNode);
}
This delegate is registered to receive the EvtData_New_Render_Component event,
which is sent from the render component. Any actor that has a render component
will trigger this event, which includes the actor ID and the scene node for the actor.
Search WWH ::




Custom Search