/** * @inheritDoc */ void DefinitionService::parseSystems(void) { ASSERT(m_gdProto.systems_size() > 0); for (auto system : m_gdProto.systems()) { loadSystemLibrary(system.type(), &m_pSystem); ASSERT(m_pSystem != NULL); // Get the default properties from system, then Initialize it m_pSystem->setProperties(system.properties()); m_pSystem->initialize(); ASSERTMSG1(system.type() == m_pSystem->GetSystemType(), "Parser identified an incorrect system type. It should be %s.", Proto::SystemType_Name(m_pSystem->GetSystemType())); } }
/** * @inheritDoc */ Error DefinitionService::loadSystemLibrary(Proto::SystemType type, ISystem** ppSystem) { Error Err = Errors::Failure; std::string libraryName = Proto::SystemType_Name(type) + "System"; HMODULE hLib = LoadLibraryA(libraryName.c_str()); if (hLib == NULL) { ASSERTMSG1(false, "Failed to load system %s", libraryName); return Err; } InitializeSystemLibFunction fnInitSystemLib = reinterpret_cast<InitializeSystemLibFunction>(GetProcAddress(hLib, "InitializeSystemLib")); if (fnInitSystemLib != NULL) { fnInitSystemLib(IServiceManager::get()); } CreateSystemFunction fnCreateSystem = reinterpret_cast<CreateSystemFunction>(GetProcAddress(hLib, "CreateSystem")); if (fnCreateSystem == NULL) { return Err; } ISystem* pSystem = fnCreateSystem(); if (pSystem == NULL) { return Err; } SystemService* systemService = IServiceManager::get()->getSystemService(); Proto::SystemType systemType = pSystem->GetSystemType(); ISystem* pCurrSystem = systemService->get(systemType); if (pCurrSystem != NULL) { return Err; } systemService->add(pSystem); SystemLib systemLib = { reinterpret_cast<Handle>(hLib), pSystem }; m_systemLibs.push_back(systemLib); *ppSystem = pSystem; return Errors::Success; }
void test_FixedSizeBufferSet() { const int NSIZE = 1024*1024; const int NELEM = NSIZE + 1024; long double time0, time1; ftl::FixedSizePoolSet pool(sizeof(int), NSIZE); int **buf = new int*[NELEM]; int i; time0 = GetTimeMicroSec(); for(i=0; i < NELEM; ++i) { buf[i] = (int*)pool.allocate(); ASSERTMSG2(buf[i], "%d", i); } printf("pools_count:%d capacity:%d size:%d\n", pool.pools_count(), pool.capacity(), pool.size()); for(i=0; i < NELEM; ++i) { pool.deallocate(buf[i]); } time1 = GetTimeMicroSec(); ASSERTMSG1(0==pool.size(), "size==0"); printf("FixedSizePoolSet :%d timing:%d\n", i, int(time1-time0)); time0 = GetTimeMicroSec(); for(i=0; i < NELEM; ++i) { buf[i] = new int;; assert(buf[i]); } for(i=0; i < NELEM; ++i) { delete buf[i]; } time1 = GetTimeMicroSec(); printf("c++ new :%d timing:%d\n", i, int(time1-time0)); ASSERTMSG0(pool.size()==0); delete[] buf; }
/** * @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); } } }