コード例 #1
0
/**
 * @inheritDoc
 */
void DefinitionService::parseScene(std::string sScene) {
    const auto& scenes = m_gdProto.scenes();
    auto sceneIt = std::find(scenes.begin(), scenes.end(), sScene);
    if (sceneIt == scenes.end()) {
        return;
    }
    
    SystemService* systemService = IServiceManager::get()->getSystemService();
    
    //
    // Create the initial scene for each system.
    //
    for (auto it : systemService->get()) {
        m_pScene->Extend(it.second);
    }

    //
    // Parse the SDF file
    //
    Proto::Scene scene;
    Error result = loadProto(*sceneIt + ".sdf.bin", &scene);
    ASSERT(result == Errors::Success);

    //
    // Initialize the scene templates.
    //
    m_pScene->addTemplates(&scene.templates());

    //
    // Initialize the System scenes.
    //
    for (auto system : scene.systems()) {
        m_pSystem = systemService->get(system.type());
        ASSERTMSG1(m_pSystem != NULL, "Parser was unable to get system %s.", Proto::SystemType_Name(system.type()));

        if (m_pSystem != NULL) {
            auto it = m_pScene->GetSystemScenes().find(m_pSystem->GetSystemType());
            ASSERTMSG1(it != m_pScene->GetSystemScenes().end(), "Parser was unable to find a scene for system %s.", Proto::SystemType_Name(system.type()));
            m_pSystemScene = it->second;
            ASSERT(m_pSystemScene != NULL);
            // Initialize system scene properties
            m_pSystemScene->setProperties(system.properties());
            m_pSystemScene->initialize();
        }
    }

    //
    // Initialize the scene objects.
    //
    for (auto object : scene.objects()) {
        m_pScene->createObject(&object);
    }

    //
    // Refresh all scenes
    // 
    for (auto scene : m_pScene->GetSystemScenes()) {
        scene.second->GlobalSceneStatusChanged(ISystemScene::PostLoadingObjects);
    }

    //
    // Initialize the links.
    //
    for (auto link : scene.links()) {
        UObject* pSubject = m_pScene->FindObject(link.subject().c_str());
        UObject* pObserver = m_pScene->FindObject(link.observer().c_str());

        //
        // Get the extension for the object.
        //
        ISystemObject* pSystemObserver = pSystemObserver = pObserver->GetExtension(link.observersystemtype());

        //
        // Call the scene to register the links.
        //
        if (link.subjectsystemtype() != Proto::SystemType::Null) {
            ISystemObject* pSystemSubject = pSystemSubject = pSubject->GetExtension(link.subjectsystemtype());
            m_pScene->CreateObjectLink(pSystemSubject, pSystemObserver);
        } else {
            m_pScene->CreateObjectLink(pSubject, pSystemObserver);
        }
    }
}