////////////////////////////////////////////////////////////////////////// // // Class ModelManagerSlaver // void ModelManagerWrapper::AddMesh( const std::wstring& meshID, const std::wstring& meshFilename, const std::wstring& textureFilename ) { ModelManager* pModelMan = MyIrrlichtEngine::GetEngine()->GetModelManager(); pModelMan->AddMesh( meshID, meshFilename, textureFilename ); }
bool RobotBrainServiceService::start(int argc, char* argv[]) { char adapterStr[255]; //Create the topics SimEventsUtils::createTopic(communicator(), "SalientPointMessageTopic"); //Create the adapter sprintf(adapterStr, "default -p %i", RobotBrainObjects::RobotBrainPort); itsAdapter = communicator()->createObjectAdapterWithEndpoints("SaliencyModule", adapterStr); //Create the manager and its objects itsMgr = new ModelManager("SaliencyModuleService"); LINFO("Starting SaliencyModule"); nub::ref<SaliencyModuleI> ret(new SaliencyModuleI(*itsMgr)); itsMgr->addSubComponent(ret); ret->init(communicator(), itsAdapter); itsMgr->parseCommandLine((const int)argc, (const char**)argv, "", 0, 0); itsAdapter->activate(); itsMgr->start(); return true; }
bool SeaBee3GUIService::start(int argc, char* argv[]) { QApplication app(argc, argv); itsMgr = new ModelManager("SeaBeeIIIGUIManager"); char adapterStr[255]; LINFO("Creating Adapter"); sprintf(adapterStr, "default -p %i", 12345); itsAdapter = communicator()->createObjectAdapterWithEndpoints("RobotBrainPort", adapterStr); nub::ref<MainWindow> mainWindow(new MainWindow(*itsMgr)); itsMgr->addSubComponent(mainWindow); LINFO("Starting Up GUI Comm"); mainWindow->initIce(communicator(), itsAdapter); itsMgr->parseCommandLine(argc, argv, "", 0, 0); itsAdapter->activate(); itsMgr->start(); mainWindow->setGeometry(100,100,900,800); mainWindow->show(); return app.exec(); }
void CompanyWidget::setup(int companyType, bool isFin, bool isContact, bool isAdd, bool isLabel) { ui->finFrame->setHidden(!isFin); ui->contactFrame->setHidden(!isContact); ui->addCompany->setHidden(!isAdd); ui->typeLabel->setHidden(!isLabel); this->companyType = companyType; ModelManager *models = ModelManager::getInstance(); if (isContact) { contactF = new SortFilterModel(this); contactF->setFilterRole(ContactModel::companyIdRole); contactF->setSourceModel(models->getContactModel()); ui->contact->setModel(contactF); } SortFilterModel *companyF = new SortFilterModel(this); companyF->setFilterRole(CompanyModel::typeRole); companyF->setMatchValue(companyType); companyF->setSourceModel(models->getCompanyModel()); ui->company->setModel(companyF); if (companyType == Company::CUSTOMER) { ui->typeLabel->setText(QString::fromUtf8("Заказчики")); } else if (companyType == Company::SUPPLIER) { ui->typeLabel->setText(QString::fromUtf8("Поставщики")); } else if (companyType == -1) { ui->typeLabel->setText(QString::fromUtf8("Компании")); } }
bool RobotBrainServiceService::start(int argc, char* argv[]) #endif { MYLOGVERB = LOG_INFO; char adapterStr[255]; //Create the adapter int port = RobotBrainObjects::RobotBrainPort; bool connected = false; // try to connect to ports until successful LDEBUG("Opening Connection"); while(!connected) { try { LINFO("Trying Port:%d", port); sprintf(adapterStr, "default -p %i", port); itsAdapter = communicator()->createObjectAdapterWithEndpoints ("GistSal_Navigation", adapterStr); connected = true; } catch(Ice::SocketException) { port++; } } //Create the manager and its objects itsMgr = new ModelManager("BeoLocalizationService"); LINFO("Starting BeoLocalization System"); nub::ref<BeoLocalizer> bl(new BeoLocalizer (*itsMgr, "BeoLocalizer", "BeoLocalizer")); LINFO("BeoLocalizer created"); itsMgr->addSubComponent(bl); LINFO("BeoLocalizer Added As a subcomponent"); bl->init(communicator(), itsAdapter); LINFO("BeoLocalizer initiated"); // check command line inputs/options if (itsMgr->parseCommandLine((const int)argc, (const char**)argv, "", 0, 0) == false) return(1); // FIXXX: in the future the map should be specificable // from the command line to allow for stand alone application // check app-Beobot2_GistSalLocalizer.C // activate manager and adapter itsAdapter->activate(); itsMgr->start(); return true; }
bool RobotBrainServiceService::start(int argc, char* argv[]) { char adapterStr[255]; //Create the adapter int port = RobotBrainObjects::RobotBrainPort; bool connected = false; while(!connected) { try { LINFO("Trying Port:%d", port); sprintf(adapterStr, "default -p %i", port); itsAdapter = communicator()->createObjectAdapterWithEndpoints("SeaBee3SimulatorAdapter", adapterStr); connected = true; } catch(Ice::SocketException) { port++; } } //Create the manager and its objects itsMgr = new ModelManager("SeaBee3SimulatorServiceManager"); nub::ref<OutputFrameSeries> ofs(new OutputFrameSeries(*itsMgr)); itsMgr->addSubComponent(ofs); LINFO("Starting SeaBee3 Simulator"); nub::ref<SeaBee3Simulator> subSim(new SeaBee3Simulator(*itsMgr, "SeaBee3Simulator", "SeaBee3Simulator")); itsMgr->addSubComponent(subSim); subSim->init(communicator(), itsAdapter); itsMgr->parseCommandLine((const int)argc, (const char**)argv, "", 0, 0); itsAdapter->activate(); itsMgr->start(); while(1){ Layout<PixRGB<byte> > outDisp; subSim->simLoop(); Image<PixRGB<byte> > forwardCam = flipVertic(subSim->getFrame(1)); Image<PixRGB<byte> > downwardCam = flipVertic(subSim->getFrame(2)); outDisp = vcat(outDisp, hcat(forwardCam, downwardCam)); ofs->writeRgbLayout(outDisp, "subSim", FrameInfo("subSim", SRC_POS)); handle_keys(ofs, subSim); } return true; }
bool RobotBrainServiceService::start(int argc, char* argv[]) #endif { MYLOGVERB = LOG_INFO; char adapterStr[255]; //Create the topics // SimEventsUtils::createTopic(communicator(), "BeoGPSMessageTopic"); //Create the adapter int port = RobotBrainObjects::RobotBrainPort; bool connected = false; // try to connect to ports until successful LDEBUG("Opening Connection"); while(!connected) { try { LINFO("Trying Port:%d", port); sprintf(adapterStr, "default -p %i", port); itsAdapter = communicator()->createObjectAdapterWithEndpoints ("BeoGPS", adapterStr); connected = true; } catch(Ice::SocketException) { port++; } } //Create the manager and its objects itsMgr = new ModelManager("BeoGPSService"); LINFO("Starting BeoGPS System"); nub::ref<BeoGPS> gps(new BeoGPS(*itsMgr, "BeoGPS", "BeoGPS")); LINFO("BeoGPS created"); itsMgr->addSubComponent(gps); LINFO("BeoGPS Added As a subcomponent"); gps->init(communicator(), itsAdapter); LINFO("BeoGPS initiated"); // check command line inputs/options if (itsMgr->parseCommandLine (argc, argv, "<serdev>", 0, 0) == false) return(1); // let's configure our serial device: // gps->configureSerial(itsMgr->getExtraArg(0)); // LINFO("Using: %s", itsMgr->getExtraArg(0).c_str()); // activate manager and adapter itsAdapter->activate(); itsMgr->start(); return true; }
MsgDialog::MsgDialog(QWidget *parent) : QDialog(parent), ui(new Ui::MsgDialog) { ui->setupUi(this); ModelManager *models = ModelManager::getInstance(); ui->clients->setModel(models->getClientModel()); }
PythonSceneNode ModelManagerWrapper::AddSceneNodeByMeshID( const std::wstring& meshID, bool bTestCollision /*= false */ ) { ModelManager* pModelMan = MyIrrlichtEngine::GetEngine()->GetModelManager(); PythonSceneNode node; scene::ISceneNode* pNode = pModelMan->AddSceneNodeFromMesh( meshID, bTestCollision ); node.ptr = pNode; //pNode->drop(); // 引用减一 return node; }
int main(const int argc, const char **argv) { MYLOGVERB = LOG_INFO; ModelManager *mgr = new ModelManager("Extract Patches for Hmax with Feature Learning"); mgr->exportOptions(MC_RECURSE); // required arguments // <c1patchesDir> <trainPosDir> if (mgr->parseCommandLine( (const int)argc, (const char**)argv, "<c1patchesDir> <trainPosDir>", 2, 2) == false) return 1; // Create a temp HmaxFL object to extract C1Patches std::vector<int> c1ScaleSS(2); c1ScaleSS[0] = 1; c1ScaleSS[1] = 3; std::vector<int> c1SpaceSS(2); c1SpaceSS[0] = 10; c1SpaceSS[1] = 11; // desired frame sizes [11 and 13] HmaxFL hmax(NORI,c1SpaceSS,c1ScaleSS,2,true,1.0F,1.0F,0.3F,4.05F,-0.05F,11,2); std::string c1PatchesBaseDir; std::string trainPosName; // Directory where positive images are c1PatchesBaseDir = mgr->getExtraArg(0); trainPosName = mgr->getExtraArg(1); // Extract random patches from a set of images in a positive training directory std::vector<std::string> trainPos = hmax.readDir(trainPosName); int posTrainSize = trainPos.size(); //Image<byte> inputb; Image<float> trainPosImage; std::cout << "Scanned training and testing images" << std::endl; std::vector<int> pS(4); pS[0] = 4; pS[1] = 8, pS[2] = 12; pS[3] = 16; std::srand(time(0)); for(int i=0;i<NUM_PATCHES_PER_SIZE;i++){ // Randomly select an image from the list unsigned int imInd = static_cast<unsigned int>(floor((rand()-1.0F)/RAND_MAX*posTrainSize)); trainPosImage = Raster::ReadFloat(trainPos[imInd]); // Learn the appropriate simple S2 patches from the C1 results hmax.extractRandC1Patch(c1PatchesBaseDir,trainPosImage,i,pS); } std::cout << "Completed extraction of C1 Patches" << std::endl; return 0; }
void ToolWidget::on_ambientButton_clicked() { ModelManager* model = mainWindow->getModelManager(); if (!model->openLight()) { QMessageBox::critical(this, "Error", "Fail to open new light"); } mainWindow->getViewManager()->repaintAll(); ui->ambientButton->setEnabled(model->canOpenLight()); updateLightBox(); updateLightCanOpen(); }
void ToolWidget::on_tabWidget_currentChanged(QWidget *arg1) { if (arg1 == ui->solidTab) { mainWindow->getModelManager()->selectSolid(selectedSolid); mainWindow->getViewManager()->repaintAll(); } else if (arg1 == ui->primitiveTab) { ModelManager* model = mainWindow->getModelManager(); ASolid* solid = model->getSolidFromPmt(selectedPrimitive); model->selectSolid(solid); mainWindow->getViewManager()->repaintAll(); } }
void ModelPanel::LoadDataFromScene() { ModelManager* modelMgr = gEngine->GetModelManager(); std::list<Model*> modelList = modelMgr->GetModelList(); wxTreeItemId rootId = mTreeCtrl->AddRoot(L"root", 0, 0, New ModelTreeItemData(NULL)); for(std::list<Model*>::iterator iter = modelList.begin(); iter != modelList.end(); ++iter) { Model* model = *iter; appendModel(rootId, model); } }
void ToolWidget::on_visiblePmtBtn_clicked() { ModelManager* model = mainWindow->getModelManager(); ASolid* solid = model->getSolidFromPmt(selectedPrimitive); if (solid) { solid->setVisible(!solid->getVisible()); mainWindow->getViewManager()->repaintAll(); if (ui->visiblePmtBtn->text() == "Hide") { ui->visiblePmtBtn->setText("Show"); } else { ui->visiblePmtBtn->setText("Hide"); } } }
bool RobotBrainServiceService::start(int argc, char* argv[]) { char adapterStr[255]; LINFO("Creating Topic!"); //Create the topics // SimEventsUtils::createTopic(communicator(), "BinFinderMessageTopic"); //Create the adapter int port = RobotBrainObjects::RobotBrainPort; bool connected = false; LDEBUG("Opening Connection"); while(!connected) { try { LINFO("Trying Port:%d", port); sprintf(adapterStr, "default -p %i", port); itsAdapter = communicator()->createObjectAdapterWithEndpoints ("BinFinder", adapterStr); connected = true; } catch(Ice::SocketException) { port++; } } //Create the manager and its objects itsMgr = new ModelManager("BinFinderService"); LINFO("Starting BinFinder"); nub::ref<BinFinder> ret (new BinFinder(*itsMgr, "BinFinder1", "BinFinder2")); LINFO("BinFinder Created"); itsMgr->addSubComponent(ret); LINFO("BinFinder Added As Sub Component"); ret->init(communicator(), itsAdapter); LINFO("BinFinder Inited"); itsMgr->parseCommandLine((const int)argc, (const char**)argv, "", 0, 0); itsAdapter->activate(); itsMgr->start(); return true; }
bool Predictor::Store(std::ostream& os) { ModelManagerFactory mmf(ModelManager::PARAMFILE); ModelManager* pModelManager = mmf.Make(); if(!pModelManager) { TERR("unable to make ModelManager."); return false; } bool bRet = pModelManager->Store(mpTreeBoost, os); if(pModelManager) delete pModelManager; return bRet; }
// ###################################################################### bool RobotBrainServiceService::start(int argc, char* argv[]) { MYLOGVERB = LOG_INFO; char adapterStr[255]; //Create the adapter int port = RobotBrainObjects::RobotBrainPort; bool connected = false; // try to connect to ports until successful LDEBUG("Opening Connection"); while(!connected) { try { LINFO("Trying Port:%d", port); sprintf(adapterStr, "default -p %i", port); itsAdapter = communicator()->createObjectAdapterWithEndpoints ("RG_Lane", adapterStr); connected = true; } catch(Ice::SocketException) { port++; } } //Create the manager and its objects itsMgr = new ModelManager("RG_LaneService"); LINFO("Starting RG_Lane System"); nub::ref<RG_Lane> nav(new RG_Lane(*itsMgr, "RG_Lane", "RG_Lane")); LINFO("RG_Lane created"); itsMgr->addSubComponent(nav); LINFO("RG_Lane Added As a subcomponent"); nav->init(communicator(), itsAdapter); LINFO("RG_Lane initiated"); // check command line inputs/options itsMgr->parseCommandLine(argc, argv, "", 0, 0); // activate manager and adapter itsAdapter->activate(); itsMgr->start(); return true; }
void ModelDisplayState::PrepareStaticModels(ModelManager& modelManager, const ModelBlueprint& blueprint) { const std::vector<CompositeModel3d::StaticModelData>& vecStaticModels = m_spModel->StaticList(); // blueprint must contain same number of statics as composite models ATLASSERT(blueprint.m_vecStaticBlueprints.size() == vecStaticModels.size()); m_vecStaticModelTextures.resize(vecStaticModels.size()); for (size_t i=0, iMax=vecStaticModels.size(); i<iMax; i++) { // static model must contain only one material; get texture name of it CString cszTexture = vecStaticModels[i].m_spStatic->SingleMaterialTextureName(); cszTexture.Replace(_T(".\\"), _T("")); // add texture name prefix, if any const ModelBlueprint::StaticModelBlueprint& staticBlueprint = blueprint.m_vecStaticBlueprints[i]; if (!staticBlueprint.m_cszStaticTexturePrefix.IsEmpty()) cszTexture = staticBlueprint.m_cszStaticTexturePrefix + cszTexture; m_vecStaticModelTextures[i] = modelManager.LoadTexture(cszTexture); } }
bool RobotBrainServiceService::start(int argc, char* argv[]) { char adapterStr[255]; LINFO("Starting XBox Controller..."); //Create the topics // SimEventsUtils::createTopic(communicator(), "XBox360RemoteControlMessageTopic"); //Create the adapter int port = RobotBrainObjects::RobotBrainPort; bool connected = false; while(!connected) { try { LINFO("Trying Port:%d", port); sprintf(adapterStr, "default -p %i", port); itsAdapter = communicator()->createObjectAdapterWithEndpoints("XBox360RemoteControl", adapterStr); connected = true; } catch(Ice::SocketException) { port++; } } //Create the manager and its objects itsMgr = new ModelManager("XBox360RemoteControlService"); LINFO("Starting XBox360RemoteControl"); nub::ref<XBox360RemoteControlI> ret(new XBox360RemoteControlI(0, *itsMgr, "XBox360RemoteControl1", "XBox360RemoteControl2")); LINFO("XBox360RemoteControl Created"); itsMgr->addSubComponent(ret); LINFO("XBox360RemoteControl Added As Sub Component"); ret->init(communicator(), itsAdapter); LINFO("XBox360RemoteControl Inited"); itsMgr->parseCommandLine((const int)argc, (const char**)argv, "", 0, 0); itsAdapter->activate(); itsMgr->start(); return true; }
Eigen::VectorXd ObservableSpinSpinCorrelation::get_current( const ModelManager& model, ObservableCache& cache ) const { if ( !cache.s ) { cache.s = model.s(); } return cache.s.get().cast<double>(); }
void addModelToSolution(const std::shared_ptr<Model>& model, const Remapper& remapper, ModelManager& solution, Printer& printer) { auto outmodel = new Model(); outmodel->literalinterpretations = getBackMappedModel(model->literalinterpretations, remapper); outmodel->variableassignments = getBackMappedModel(model->variableassignments, remapper); solution.addModel(outmodel); printer.addModel(outmodel); }
int main(int argc, char **argv) { // glut init glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); // create window glutInitWindowPosition(500, 100); glutInitWindowSize(600, 600); glutCreateWindow("10420 CS550000 CG HW2 Haley"); glewInit(); if(glewIsSupported("GL_VERSION_2_0")){ printf("Ready for OpenGL 2.0\n"); } else{ printf("OpenGL 2.0 not supported\n"); system("pause"); exit(1); } mm.showHelpMenu(); puts("\n\n ====== Translation Mode Start ======\n"); mm.startManaging(); // register glut callback functions glutDisplayFunc(onDisplay); glutIdleFunc(onIdle); glutKeyboardFunc(onKeyboard); glutSpecialFunc(onKeyboardSpecial); glutMouseFunc(onMouse); glutMotionFunc(onMouseMotion); glutReshapeFunc(onWindowReshape); // set up shaders here setShaders(); glEnable(GL_DEPTH_TEST); // main loop glutMainLoop(); return 0; }
int nocturn::runNoctrun(int argc, char** argv) { app = new QApplication(argc, argv); app->setApplicationName("Nocturn"); QStringList args = app->arguments(); bool autoLoadMode = false; QStringList path; if (args.count() >= 3 and args.at(1) == "-f" and args.at(2) != "") { for (unsigned i = 2; i < argc; ++i) { path << args.at(i); } autoLoadMode = true; } SettingsManager Settings; ModelManager Manager; MainControler Controler(&Manager); MainView View(Manager.getPlaybackManager()->getPlaybackModel(), autoLoadMode); connect(app, SIGNAL(aboutToQuit()), this, SLOT(quitNocturn()) ); connect(app, SIGNAL(aboutToQuit()), &Controler, SLOT(quitNocturn())); Manager.getPlayListManager()->restorePlayListFromFiles(); if (autoLoadMode) { Manager.getPlayListManager()->autoLoadPath(path); } connect(Manager.getPlayListManager(), SIGNAL(CurrentSongChanged(const QString&)), &View, SLOT(updateWindowTitle(const QString&))); View.setFirstTab(); SysTrayIconWrapper Icon(View, *(Manager.getPlayListManager())); return app->exec(); }
void ModelDisplayState::PrepareAnimatedModelTextures(ModelManager& modelManager, const ModelBlueprint& blueprint) { AnimatedModel3d& model = *m_spModel->GetAnimated(); Data& data = model.GetData(); // prepare textures for each material m_vecMaterialTextureData.resize(data.m_vecMaterials.size()); ATLASSERT(blueprint.m_vecAnimatedMaterialTextures.size() == data.m_vecMaterials.size()); for (size_t i=0, iMax=m_vecMaterialTextureData.size(); i<iMax; i++) { const Material& material = data.m_vecMaterials[i]; CString cszTexture = material.cszTexture; cszTexture.Replace(_T(".\\"), _T("")); // use blueprint texture name, if set if (!blueprint.m_vecAnimatedMaterialTextures[i].IsEmpty()) cszTexture = blueprint.m_vecAnimatedMaterialTextures[i]; m_vecMaterialTextureData[i].m_spTexture = modelManager.LoadTexture(cszTexture); } }
void MassSpriteModel::restore() { _TRACE3_("_model_name=" << _model_name << " start"); ModelManager* pModelManager = pGOD->_pModelManager; HRESULT hr; if (!_paVtxBuffer_data_model) { //静的な情報設定 std::vector<std::string> names = UTIL::split(std::string(_model_name), ","); std::string xfile_name = ""; //読み込むXファイル名 if (names.size() == 1) { _TRACE_(FUNC_NAME<<" "<<_model_name<<" の最大同時描画オブジェクト数は、デフォルトの"<<GGAFDXMASS_MAX_INSTANCE_NUM<<" が設定されました。"); _set_num = GGAFDXMASS_MAX_INSTANCE_NUM; xfile_name = ModelManager::getSpriteFileName(names[0], "sprx"); } else if (names.size() == 2) { _set_num = STOI(names[0]); xfile_name = ModelManager::getSpriteFileName(names[1], "sprx"); } else { throwCriticalException("_model_name には \"xxxxxx\" or \"8/xxxxx\" 形式を指定してください。 \n" "実際は、_model_name="<<_model_name<<" でした。"); } if (_set_num < 1 || _set_num > GGAFDXMASS_MAX_INSTANCE_NUM) { throwCriticalException(_model_name<<"の最大同時描画オブジェクト数が不正。範囲は 1〜"<<GGAFDXMASS_MAX_INSTANCE_NUM<<"セットです。_set_num="<<_set_num); } if (xfile_name == "") { throwCriticalException("スプライト定義ファイル(*.sprx)が見つかりません。model_name="<<(_model_name)); } ModelManager::SpriteXFileFmt xdata; pModelManager->obtainSpriteInfo(&xdata, xfile_name); _model_width_px = xdata.width; _model_height_px = xdata.height; _model_half_width_px = _model_width_px/2; _model_half_height_px = _model_height_px/2; _row_texture_split = xdata.row_texture_split; _col_texture_split = xdata.col_texture_split; _nVertices = 4; _nFaces = 2; _paVtxBuffer_data_model = NEW MassSpriteModel::VERTEX_model[_nVertices]; _size_vertex_unit_model = sizeof(MassSpriteModel::VERTEX_model); _size_vertices_model = sizeof(MassSpriteModel::VERTEX_model) * _nVertices; // float tex_width = (float)(model_pTextureConnection->peek()->_pD3DXIMAGE_INFO->Width); //テクスチャの幅(px) // float tex_height = (float)(model_pTextureConnection->peek()->_pD3DXIMAGE_INFO->Height); //テクスチャの高さ(px) double du = 0.0; double dv = 0.0; //左上 _paVtxBuffer_data_model[0].x = PX_DX(xdata.width) / -2.0; _paVtxBuffer_data_model[0].y = PX_DX(xdata.height) / 2.0; _paVtxBuffer_data_model[0].z = 0.0f; _paVtxBuffer_data_model[0].nx = 0.0f; _paVtxBuffer_data_model[0].ny = 0.0f; _paVtxBuffer_data_model[0].nz = -1.0f; _paVtxBuffer_data_model[0].tu = du; _paVtxBuffer_data_model[0].tv = dv; //右上 _paVtxBuffer_data_model[1].x = PX_DX(xdata.width) / 2.0; _paVtxBuffer_data_model[1].y = PX_DX(xdata.height) / 2.0; _paVtxBuffer_data_model[1].z = 0.0f; _paVtxBuffer_data_model[1].nx = 0.0f; _paVtxBuffer_data_model[1].ny = 0.0f; _paVtxBuffer_data_model[1].nz = -1.0f; _paVtxBuffer_data_model[1].tu = (1.0/xdata.col_texture_split) - du; _paVtxBuffer_data_model[1].tv = dv; //左下 _paVtxBuffer_data_model[2].x = PX_DX(xdata.width) / -2.0; _paVtxBuffer_data_model[2].y = PX_DX(xdata.height) / -2.0; _paVtxBuffer_data_model[2].z = 0.0f; _paVtxBuffer_data_model[2].nx = 0.0f; _paVtxBuffer_data_model[2].ny = 0.0f; _paVtxBuffer_data_model[2].nz = -1.0f; _paVtxBuffer_data_model[2].tu = du; _paVtxBuffer_data_model[2].tv = (1.0/xdata.row_texture_split) - dv; //右下 _paVtxBuffer_data_model[3].x = PX_DX(xdata.width) / 2.0; _paVtxBuffer_data_model[3].y = PX_DX(xdata.height) / -2.0; _paVtxBuffer_data_model[3].z = 0.0f; _paVtxBuffer_data_model[3].nx = 0.0f; _paVtxBuffer_data_model[3].ny = 0.0f; _paVtxBuffer_data_model[3].nz = -1.0f; _paVtxBuffer_data_model[3].tu = 1.0/xdata.col_texture_split; _paVtxBuffer_data_model[3].tv = 1.0/xdata.row_texture_split; _paIndexBuffer_data = NEW WORD[(_nFaces*3)]; _paIndexBuffer_data[0] = 0; _paIndexBuffer_data[1] = 1; _paIndexBuffer_data[2] = 2; _paIndexBuffer_data[3] = 1; _paIndexBuffer_data[4] = 3; _paIndexBuffer_data[5] = 2; //距離 FLOAT model_bounding_sphere_radius = (FLOAT)(sqrt(_paVtxBuffer_data_model[0].x * _paVtxBuffer_data_model[0].x + _paVtxBuffer_data_model[0].y * _paVtxBuffer_data_model[0].y + _paVtxBuffer_data_model[0].z * _paVtxBuffer_data_model[0].z)); _bounding_sphere_radius = model_bounding_sphere_radius; setMaterial(); _pa_texture_filenames[0] = std::string(xdata.texture_file); } //デバイスに頂点バッファ作成(モデル) if (_pVertexBuffer_model == nullptr) { hr = God::_pID3DDevice9->CreateVertexBuffer( _size_vertices_model, D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &(_pVertexBuffer_model), nullptr); checkDxException(hr, D3D_OK, "_pID3DDevice9->CreateVertexBuffer 失敗 model="<<(_model_name)); //バッファへ作成済み頂点データを流し込む void* pDeviceMemory = 0; hr = _pVertexBuffer_model->Lock(0, _size_vertices_model, (void**)&pDeviceMemory, 0); checkDxException(hr, D3D_OK, "頂点バッファのロック取得に失敗 model="<<_model_name); memcpy(pDeviceMemory, _paVtxBuffer_data_model, _size_vertices_model); hr = _pVertexBuffer_model->Unlock(); checkDxException(hr, D3D_OK, "頂点バッファのアンロック取得に失敗 model="<<_model_name); } //デバイスにインデックスバッファ作成 if (_pIndexBuffer == nullptr) { hr = God::_pID3DDevice9->CreateIndexBuffer( sizeof(WORD) * _nFaces * 3, D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &(_pIndexBuffer), nullptr); checkDxException(hr, D3D_OK, "_pID3DDevice9->CreateIndexBuffer 失敗 model="<<_model_name); void* pDeviceMemory = 0; hr = _pIndexBuffer->Lock(0, 0, (void**)&pDeviceMemory,0); checkDxException(hr, D3D_OK, "インデックスバッファのロック取得に失敗 model="<<_model_name); memcpy(pDeviceMemory, _paIndexBuffer_data, sizeof(WORD)*_nFaces*3); hr = _pIndexBuffer->Unlock(); checkDxException(hr, D3D_OK, "インデックスバッファのアンロック取得に失敗 model="<<_model_name); } //デバイスにテクスチャ作成 if (!_papTextureConnection) { _papTextureConnection = NEW TextureConnection*[_num_materials]; for (DWORD n = 0; n < _num_materials; n++) { _papTextureConnection[n] = (TextureConnection*)(pModelManager->_pModelTextureManager->connect(_pa_texture_filenames[n].c_str(), this)); } }
void WMOModelInstance::unloadModel(ModelManager &mm) { mm.delbyname(filename); model = 0; }
void WMOModelInstance::loadModel(ModelManager &mm) { model = (WoWModel*)mm.items[mm.add(GAMEDIRECTORY.getFile(filename))]; model->isWMO = true; }
void Renderer::LoadModels(void) { ModelManager* pMM = ModelManager::GetInstance(); // Load Level Geometry pMM->LoadModel("Resource/Level Geo/FFP_3D_AbandonedCart_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_ACDuct_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_BakerySign_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_BasicCutoutA_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_BasicCutoutB_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_BasicCutoutC_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_BoysRestroom_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_ButcherBakeryWindow_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_ButcherSign_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_CardBoardBoxes_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_CeilingSet0_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_CeilingSet1_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_DairyItems_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_DeliSign_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_DeliWindow_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_EmployeeDoor_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_EmployeeOfTheMonth_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_Endcap_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_ExitSign_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_FloorSet0_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_FloorSet1_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_FloorSet2_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_FloorSet3_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_FloorSet4_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_FloorSet5_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_FloorSet6_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_FloorSet7_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_FloorSet8_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_FloorSet9_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_FloorTrim_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_FrontDoor_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_FSDCircleL_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_FSDCircleM_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_FSDCircleS_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_FSDSquareL_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_FSDSquareM_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_FSDSquareS_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_GirlsRestroom_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_GlassCounter_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_GlassFreezer_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_HalfWall_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_HelpDesk_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_LightFixtures_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_LobsterCutout_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_LobsterTank_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_MeatSection_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_OpenFreezerLeft_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_OpenFreezerRight_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_Outside_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_Pallet_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_Pirate_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_ProduceLeft_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_ProduceRight_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_Register_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_Shelf_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_ShelfStuff_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_Snowman_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_StartingLine_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_Umbra_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_WallSet0_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_WallSet1_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_WallSupports_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_BreakUpSign0_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_BreakUpSign1_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_Alien_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_LittleEvelyns_FIN.mesh"); // these meshes will be sharing a texture and render context, so they will be a special case when loading the level /*pMM->LoadModel("Resource/Level Geo/FFP_3D_BasicCutoutA_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_BasicCutoutB_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_BasicCutoutC_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_StartBanner_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_StartFrame0_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_StartFrame1_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_StartLight0_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_StartLight1_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_StartLight2_FIN.mesh"); pMM->LoadModel("Resource/Level Geo/FFP_3D_StartLight3_FIN.mesh");*/ // Collision volumes pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_CardBoardBoxes_FIN_Collision.mesh"); pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_Endcap_FIN_Collision.mesh"); pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_FrontDoor_FIN_Collision.mesh"); pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_FSDCircleL_FIN_Collision.mesh"); pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_FSDCircleM_FIN_Collision.mesh"); pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_FSDCircleS_FIN_Collision.mesh"); pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_FSDSquareL_FIN_Collision.mesh"); pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_FSDSquareM_FIN_Collision.mesh"); pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_FSDSquareS_FIN_Collision.mesh"); //pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_GlassCounter_FIN_Collision.mesh"); pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_GlassFreezer_FIN_Collision.mesh"); pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_HalfWall_FIN_Collision.mesh"); pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_HelpDesk_FIN_Collision.mesh"); pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_LobsterCutout_FIN_Collision.mesh"); //pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_LobsterTank_FIN_Collision.mesh"); pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_OpenFreezerLeft_FIN_Collision.mesh"); pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_OpenFreezerRight_FIN_Collision.mesh"); pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_Pallet_FIN_Collision.mesh"); pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_Pirate_FIN_Collision.mesh"); pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_ProduceLeft_FIN_Collision.mesh"); pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_ProduceRight_FIN_Collision.mesh"); pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_Register_FIN_Collision.mesh"); pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_Shelf_FIN_Collision.mesh"); pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_Snowman_FIN_Collision.mesh"); pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_Umbra_FIN_Collision.mesh"); pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_Alien_FIN_Collision.mesh"); pMM->LoadAABB("Resource/Collision Volumes/FFP_3D_LittleEvelyns_FIN_Collision.mesh"); // PowerUps pMM->LoadModel("Resource/PowerUps/Banana_MShape.mesh"); pMM->LoadModel("Resource/PowerUps/Chicken_NoodleSoup_MShape.mesh"); pMM->LoadModelWithBones("Resource/PowerUps/FFP_3D_DONUTS_FINShape.mesh"); pMM->LoadModel("Resource/PowerUps/FFP_3D_IceTurkeyBox_FIN.mesh"); pMM->LoadModel("Resource/PowerUps/Jam_MShape.mesh"); pMM->LoadModel("Resource/PowerUps/Peanut_butter_MShape.mesh"); pMM->LoadModel("Resource/PowerUps/Pie_MShape.mesh"); pMM->LoadModel("Resource/PowerUps/Thors_Thunder_MShape.mesh"); pMM->LoadModel("Resource/PowerUps/TurkeyShape.mesh"); pMM->LoadModel("Resource/PowerUps/FFP_3D_PeanutPile_FINShape.mesh"); pMM->LoadModel("Resource/PowerUps/Donut.mesh"); // Shadows pMM->LoadModel("Resource/Character Models/Shadows/FFP_3D_BikerShadow_FIN.mesh"); pMM->LoadModel("Resource/Character Models/Shadows/FFP_3D_BanditosShadow_FIN.mesh"); pMM->LoadModel("Resource/Character Models/Shadows/FFP_3D_LarperShadow_FIN.mesh"); pMM->LoadModel("Resource/Character Models/Shadows/FFP_3D_ScientistShadow_FIN.mesh"); pMM->LoadModel("Resource/Character Models/Shadows/FFP_3D_SashaShadow_FIN.mesh"); // Level Shadows pMM->LoadModel("Resource/Level Geo/Shadows/Shadow_Circle_Small_M.mesh"); pMM->LoadModel("Resource/Level Geo/Shadows/Shadow_Circle_Medium_M.mesh"); pMM->LoadModel("Resource/Level Geo/Shadows/Shadow_Circle_Huge_M.mesh"); pMM->LoadModel("Resource/Level Geo/Shadows/Shadow_FSD_Square_L.mesh"); pMM->LoadModel("Resource/Level Geo/Shadows/Shadow_Special.mesh"); pMM->LoadModel("Resource/Level Geo/Shadows/Shadow_Cashier_M.mesh"); pMM->LoadModel("Resource/Collision Volumes/FFP_3D_CheckoutCollision_FIN.mesh"); pMM->LoadModel("Resource/PowerUps/FFP_3D_BlueLamp_FINShape.mesh"); // 86 }
int main(){ // { // const std::string mAlign = "xxx,<><,--x"; // const int mRepeatRow = 1; // // int row = 0; // int ibeg=0, iend=0; // for(int i=0; i<mAlign.size(); ++i){ // if(mAlign[i] == ','){ // ++row; // // } // } // } #define SET4(x, a,b,c,d) x[0]=a; x[1]=b; x[2]=c; x[3]=d #define EQ4(x, a,b,c,d) (x[0]==a && x[1]==b && x[2]==c && x[3]==d) // Multidimensional data array { // basics { const int s1=5, s2=4, s3=3, s4=2; Data d(Data::INT, s1,s2,s3,s4); assert(d.hasData()); assert(d.type() == Data::INT); assert(d.sizeType() == sizeof(int)); assert(d.isNumerical()); assert(d.offset() == 0); assert(d.order() == 4); assert(d.stride() == 1); assert(d.size(0) == s1); assert(d.size(1) == s2); assert(d.size(2) == s3); assert(d.size(3) == s4); assert(d.size(0,1) == s1*s2); assert(d.size(0,1,2) == s1*s2*s3); assert(d.size(0,1,2,3) == d.size()); assert(d.indexFlat(0,0,0,0) == 0); assert(d.indexFlat(1,0,0,0) == 1); assert(d.indexFlat(0,1,0,0) == s1*1); assert(d.indexFlat(0,2,0,0) == s1*2); assert(d.indexFlat(0,0,1,0) == s2*s1*1); assert(d.indexFlat(0,0,2,0) == s2*s1*2); assert(d.indexFlat(0,0,0,1) == s3*s2*s1*1); assert(d.indexFlat(0,0,0,2) == s3*s2*s1*2); for(int i=0; i<d.size(); ++i){ int i1,i2,i3,i4; d.indexDim(i1,i2,i3,i4, i); assert(d.inBounds(i1,i2,i3,i4)); assert(d.indexFlat(i1,i2,i3,i4) == i); } for(int i=0; i<d.size(); ++i) d.assign(i, i); for(int i=0; i<d.size(); ++i) assert(d.elem<int>(i) == i); // resizing { Data e(Data::INT, 8); int N; // resize change, in bytes for(int i=0; i<e.size(); ++i) e.assign(i,i); N=e.resize(16); assert(e.sizeType()*8==N); // old elements should be copied over; extras should be zero for(int i=0; i<8 ; ++i) assert(e.at<int>(i) == i); for(int i=8; i<16; ++i) assert(e.at<int>(i) == 0); N=e.resize(0); assert(e.sizeType()*-16==N); N=e.resize(8); assert(e.sizeType()* 8==N); for(int i=0; i<e.size(); ++i) assert(e.at<int>(i) == 0); } // cloning data { Data e = d; assert(e == d); e.clone(); assert(d.elems<int>() != e.elems<int>()); assert(e == d); } // reversed slice { Data e = d.reversed(); for(int i=0; i<e.size(); ++i) assert(d.elem<int>(d.size()-1-i) == e.elem<int>(i)); e.clone(); for(int i=0; i<e.size(); ++i) assert(d.elem<int>(d.size()-1-i) == e.elem<int>(i)); e += d; for(int i=0; i<e.size(); ++i) assert(e.elem<int>(i) == e.size()-1); } } // reference counting { Data d1(Data::INT, 4,4); assert(Data::references(d1.elems<int>()) == 1); { Data d2 = d1; assert(d1.elems<int>() == d2.elems<int>()); assert(Data::references(d1.elems<int>()) == 2); } assert(Data::references(d1.elems<int>()) == 1); { Data d2 = d1.slice(1); Data d3 = d2.slice(1); assert(Data::references(d1.elems<int>()) == 3); } assert(Data::references(d1.elems<int>()) == 1); } const float cf = 10; float f = 10; std::string s = "hello"; Data d(cf); assert(d.hasData()); assert(d.size() == 1); assert(d.type() == Data::FLOAT); assert(d.at<float>(0) == cf); assert(d.toString() == "10"); assert(d.at<std::string>(0) == "10"); // d.put(std::string("8")); // assert(d.at<float>(0) == 8); // Getting/setting values d.assign(11.f); assert(d.at<float>(0) == 11.f); d.clone(); assert(d.hasData()); assert(d.size() == 1); assert(d.type() == Data::FLOAT); d.assign(11.f); assert(d.at<float>(0) == 11.f); d.assign(100); assert(d.at<float>(0) == 100); d.set(f); assert(d.elems<float>() == &f); assert(d.at<float>(0) == f); d.set(s); assert(d.type() == Data::STRING); assert(d.size() == 1); assert(d.elems<std::string>() == &s); assert(d.at<std::string>(0) == s); d.clone(); assert(d.elems<std::string>() != &s); assert(d.at<std::string>(0) == s); d.set("hello"); assert(d.type() == Data::STRING); assert(d.at<std::string>(0) == "hello"); { std::string s = "d2"; Data d2(s); d.set("d"); d2.assign(d); assert(d2.at<std::string>(0) == d.at<std::string>(0)); } { Data a(Data::FLOAT, 3); a.assign(10,0); a.assign(20,1); a.assign(30,2); float b[3]; a.copyTo(b); for(int i=0;i<3;++i) assert(b[i] == a.at<float>(i)); } // checking elements { Data::Type types[] = {Data::BOOL, Data::INT, Data::FLOAT, Data::DOUBLE}; for(int i=0;i<4;++i){ Data a(types[i], 8); a.assignAll(0); assert(a.isZero()); a.assign(1, 1); assert(!a.isZero()); a.assign(1, 3); a.assign(1, 5); a.assign(1, 7); assert(a.slice(0,4,2).isZero()); } } // searching { Data e(Data::STRING, 3); std::string s1 = "test1", s2 = "test2", s3 = "test3"; e.assign(s1, 0); e.assign(s2, 1); e.assign(s3, 2); assert(e.indexOf(s1) == 0); assert(e.indexOf(s2) == 1); assert(e.indexOf(s3) == 2); assert(e.indexOf(std::string("invalid")) == Data::npos); } // multiple element assignment { #define ASSERT_EQUALS(a,b,c,d,e)\ assert(d1.at<int>(0) == a);\ assert(d1.at<int>(1) == b);\ assert(d1.at<int>(2) == c);\ assert(d1.at<int>(3) == d);\ assert(d1.at<int>(4) == e) Data d1(Data::INT, 5); d1.assignAll(-1); ASSERT_EQUALS(-1,-1,-1,-1,-1); d1.assignAll(0); ASSERT_EQUALS(0,0,0,0,0); { float t[] = {1,2,3,4,5}; d1.assignFromArray(t,2); ASSERT_EQUALS(1,2,0,0,0); d1.assignFromArray(t+2,2,1,2); ASSERT_EQUALS(1,2,3,4,0); d1.assignAll(0); d1.assignFromArray(t,3, 2); ASSERT_EQUALS(1,3,5,0,0); d1.assignFromArray(t+1,2, 2,3); ASSERT_EQUALS(1,3,5,2,4); } #undef ASSERT_EQUALS } } // stringification { //for(int i=0;i<4;++i) printf("%g\n", f4[i]); //printf("%s\n", s1.c_str()); bool b1; float f1; double d1; std::string s1; bool b4[4]; float f4[4]; double d4[4]; std::string s4[4]; int N; // number of elements converted N=fromToken(f1, "1e-2"); assert(1==N && f1 == float(1e-2)); N=fromToken(f1, "1000"); assert(1==N && f1 == float(1000)); N=fromToken(d1, "1e-2"); assert(1==N && d1 == double(1e-2)); N=fromToken(d1, "1000"); assert(1==N && d1 == double(1000)); N=fromToken(b1, "0"); assert(1==N && b1 == 0); N=fromToken(b1, "1"); assert(1==N && b1 == 1); N=fromToken(s1, "\"test\""); assert(1==N && s1 == "test"); N=fromToken(b4,4,1, "{1,0,1,1}"); assert(4==N && EQ4(b4, 1,0,1,1)); N=fromToken(b4,4,1, "{0, 1, 0,0}"); assert(4==N && EQ4(b4, 0,1,0,0)); N=fromToken(f4,4,1, "{1, -1.2, 1e10, +.1}"); assert(4==N && EQ4(f4, 1.f,-1.2f,1e10f,+.1f)); N=fromToken(d4,4,1, "{1, -1.2, 1e10, +.1}"); assert(4==N && EQ4(d4, 1,-1.2,1e10,+.1)); N=fromToken(s4,4,1, "{\"one\", \"two\", \"three\", \"four\"}"); assert(4==N && EQ4(s4, "one","two","three","four")); N=toToken(s1, 1000.f); assert(1==N && s1 == "1000"); N=toToken(s1, 2000.0); assert(1==N && s1 == "2000"); N=toToken(s1, true); assert(1==N && s1 == "1"); N=toToken(s1, false); assert(1==N && s1 == "0"); N=toToken(s1, "test"); assert(1==N && s1 == "\"test\""); N=toToken(s1, std::string("test")); assert(1==N && s1 == "\"test\""); SET4(b4, 1,0,1,1); N=toToken(s1, b4,4,1); assert(4==N && s1 == "{1, 0, 1, 1}"); SET4(f4,-1,0.1,3,1e10); N=toToken(s1, f4,4,1); assert(4==N && s1 == "{-1, 0.1, 3, 1e+10}"); SET4(d4,-1,0.1,3,1e10); N=toToken(s1, d4,4,1); assert(4==N && s1 == "{-1, 0.1, 3, 1e+10}"); SET4(s4,"one","two","three","four"); N=toToken(s1,s4,4,1); assert(4==N && s1 == "{\"one\", \"two\", \"three\", \"four\"}"); } // test View linked list implementation { View n00, n10, n11, n20; n00.add(n10); n00.add(n11); n10.add(n20); // check all of our links assert( n00.child == &n10); assert(!n00.parent); assert(!n00.sibling); assert( n10.parent == &n00); assert( n10.sibling == &n11); assert( n10.child == &n20); assert( n11.parent == &n00); assert(!n11.child); assert(!n11.sibling); assert( n20.parent == &n10); assert(!n20.child); assert(!n20.sibling); n10.makeLastSibling(); assert(!n10.sibling); assert(n11.sibling == &n10); n11.makeLastSibling(); n10.remove(); assert(!n10.parent); assert(!n10.sibling); assert(!n00.child->sibling); n11.remove(); assert(!n00.child); assert(n10.child == &n20); } // test View memory management { View * v0d = new View; View v1s; View * v1d = new View; assert(v0d->dynamicAlloc()); assert(!v1s.dynamicAlloc()); *v0d << v1s << v1d; delete v0d; } // Notifications { bool bv1=false, bv2=false, bf=false; Notifier n; assert(n.numObservers(Update::Value) == 0); n.attach(ntSetBool1, Update::Value, &bv1); n.attach(ntSetBool2, Update::Value, &bv2); n.attach(ntSetBool1, Update::Focus, &bf); assert(n.numObservers(Update::Value) == 2); assert(n.numObservers(Update::Focus) == 1); n.notify(Update::Value); assert(bv1); assert(bv2); assert(!bf); n.notify(Update::Focus); assert(bf); bv1=bv2=false; n.detach(ntSetBool1, Update::Value, &bv1); n.notify(Update::Value); assert(!bv1); assert(bv2); bv1=bv2=false; n.detach(ntSetBool2, Update::Value, &bv2); n.notify(Update::Value); assert(!bv1); assert(!bv2); } { bool b=false; Button w; w.attach(ntValue, Update::Value, &b); w.setValue(true); assert(b); assert(w.getValue() == true); // Setting to current value should NOT send notification to avoid infinite loops b=false; w.setValue(w.getValue()); assert(!b); // Boolean model variable bool v = false; w.attachVariable(v); w.setValue(true); assert(v == true); w.setValue(false); assert(v == false); v = true; w.onDataModelSync(); assert(w.getValue() == true); w.setValue(true); assert(w.data().toToken() == "1"); w.setValue(false); assert(w.data().toToken() == "0"); w.setDataFromString("0"); assert(w.getValue() == false); w.setDataFromString("1"); assert(w.getValue() == true); assert(!w.setDataFromString("invalid")); } { Buttons w; bool b=false; w.attach(ntValue, Update::Value, &b); w.setValue(true, 0); assert(b); assert(w.getValue(0) == true); w.data().resize(2,2); w.data().assignAll(0); bool v1 = false; bool v2 = false; w.attachVariable(v1, 0); w.attachVariable(v2, 2); w.setValue(true, 0); assert(v1 == true); w.setValue(true, 2); assert(v2 == true); w.setValue(false, 0); assert(v1 == false); w.setValue(false, 2); assert(v2 == false); w.setValue(false, 0); w.setValue(false, 1); w.setValue(false, 2); w.setValue(false, 3); assert(w.data().toToken() == "{0, 0, 0, 0}"); v1 = v2 = false; w.setDataFromString("{1,1,1,1}"); assert(w.getValue(0) && w.getValue(1) && w.getValue(2) && w.getValue(3)); assert(v1 && v2); } { bool b=false; Slider w; w.attach(ntValue, Update::Value, &b); w.setValue(0.99f); assert(b); assert(w.getValue() == 0.99f); // Setting to current value should NOT send notification to avoid infinite loops b=false; w.setValue(w.getValue()); assert(!b); float v; w.attachVariable(v); w.setValue(0.99); assert(v == 0.99f); v = 0; w.onDataModelSync(); assert(w.getValue() == 0); std::string s; w.setValue(0.25); assert(w.data().toToken() == "0.25"); w.setDataFromString("0.5"); assert(w.getValue() == 0.5); assert(v == 0.5); assert(!w.setDataFromString("invalid")); assert(w.getValue() == 0.5); } { bool b=false; Sliders w(Rect(1), 2,2); w.attach(ntValue, Update::Value, &b); w.setValue(0.99f, 3); assert(b); assert(w.getValue(3) == 0.99f); float v1, v2; w.attachVariable(v1, 0); w.attachVariable(v2, 1); w.setValue(0.1f, 0); assert(v1 == 0.1f); w.setValue(0.2f, 0); assert(v1 == 0.2f); v1 = 0.8f; v2 = 0.9f; w.onDataModelSync(); assert(w.getValue(0) == 0.8f); assert(w.getValue(1) == 0.9f); w.setValue(0.1f, 0); w.setValue(0.2f, 1); w.setValue(0.3f, 2); w.setValue(0.4f, 3); assert(w.data().toToken() == "{0.1, 0.2, 0.3, 0.4}"); v1=v2=0; w.setDataFromString("{0.4,0.3,0.2,0.1}"); assert(w.getValue(0) == 0.4); assert(w.getValue(1) == 0.3); assert(w.getValue(2) == 0.2); assert(w.getValue(3) == 0.1); assert(v1 == (float)w.getValue(0) && v2 == (float)w.getValue(1)); // double vs[4] = {0.11, 0.22, 0.33, 0.44}; // w.attachVariable(vs,4); // w.onDataModelSync(); // for(int i=0; i<4; ++i) printf("%f\n", w.values()[i]); // // w.getValue(0.44, 0); // w.getValue(0.33, 0); // w.getValue(0.22, 0); // w.getValue(0.11, 0); // for(int i=0; i<4; ++i) printf("%f\n", vs[i]); } { bool b=false; Slider2D w; w.attach(ntSetBool1, Update::Value, &b); w.setValue(0.01f, 0); assert(b); assert(w.getValue(0) == 0.01f); // Setting to current value should NOT send notification to avoid infinite loops b=false; w.setValue(0.01f, 0); assert(!b); b=false; w.setValue(0.00f, 0); w.setValue(0.01f, 1); assert(b); assert(w.getValue(1) == 0.01f); b=false; w.setValueMax(); assert(b); assert(w.getValue(0) == 1.f); assert(w.getValue(1) == 1.f); float v1, v2; w.attachVariable(v1, 0); w.attachVariable(v2, 1); w.setValue(0.5f, 0); assert(v1 == 0.5f); w.setValue(0.6f, 1); assert(v2 == 0.6f); v1 = 0.1; v2 = 0.2; w.onDataModelSync(); assert(w.getValue(0) == v1); assert(w.getValue(1) == v2); w.setValue(0.2, 0); w.setValue(0.3, 1); assert(w.data().toToken() == "{0.2, 0.3}"); v1 = v2 = 0; w.setDataFromString("{0.7, 0.8}"); assert(w.getValue(0)==0.7 && w.getValue(1)==0.8); assert(v1==(float)w.getValue(0) && v2==(float)w.getValue(1)); } { bool b=false; SliderGrid<4> w; w.attach(ntValue, Update::Value, &b); w.setValue(0.01f, 0); assert(b); assert(w.getValue(0) == 0.01f); float v1, v2; w.attachVariable(v1, 0); w.attachVariable(v2, 1); w.setValue(0.1f, 0); assert(v1 == 0.1f); w.setValue(0.2f, 0); assert(v1 == 0.2f); v1 = 0.8f; v2 = 0.9f; w.onDataModelSync(); assert(w.getValue(0) == 0.8f); assert(w.getValue(1) == 0.9f); w.setValue(0.1f, 0); w.setValue(0.2f, 1); w.setValue(0.3f, 2); w.setValue(0.4f, 3); assert(w.data().toToken() == "{0.1, 0.2, 0.3, 0.4}"); v1=v2=0; w.setDataFromString("{0.4,0.3,0.2,0.1}"); assert(w.getValue(0) == 0.4); assert(w.getValue(1) == 0.3); assert(w.getValue(2) == 0.2); assert(w.getValue(3) == 0.1); assert(v1 == (float)w.getValue(0) && v2 == (float)w.getValue(1)); } { bool b=false; SliderRange w; w.attach(ntValue, Update::Value, &b); w.setValue(0.01f, 0); w.setValue(0.02f, 1); assert(b); assert(w.getValue(0) == 0.01f); assert(w.getValue(1) == 0.02f); assert(w.center() == 0.015f); assert(w.range() == 0.01f); w.endpoints(0,1); assert(w.getValue(0) == 0); assert(w.getValue(1) == 1); w.centerRange(0.5, 0.25); assert(w.getValue(0) == (0.5-0.25/2)); assert(w.getValue(1) == (0.5+0.25/2)); float v1,v2; w.attachVariable(v1, 0); w.attachVariable(v2, 1); w.setValue(0.2, 0); w.setValue(0.3, 1); assert(w.data().toToken() == "{0.2, 0.3}"); v1 = v2 = 0; w.setDataFromString("{0.7, 0.8}"); assert(w.getValue(0)==0.7 && w.getValue(1)==0.8); assert(v1==(float)w.getValue(0) && v2==(float)w.getValue(1)); } { bool b=false; Label w; w.attach(ntValue, Update::Value, &b); w.setValue("test"); assert(b); assert(w.getValue() == "test"); assert(w.data().toToken() == "\"test\""); w.setValue(""); w.setDataFromString("\"test\""); assert(w.getValue() == "test"); } { // { // double val = 1e14; // double inc = 1; // printf("%f\n", val + inc*1); // printf("%f\n", val + inc*2); // printf("%f\n", val + inc*3); // printf("%f\n", val + inc*4); // } bool b=false; NumberDialer w(1,2,1,0); w.attach(ntValue, Update::Value, &b); w.setValue(0.75); assert(b); assert(w.getValue() == 0.75); // Setting to current value should NOT send notification to avoid infinite loops b=false; w.setValue(w.getValue()); assert(!b); double v=0; w.attachVariable(v); w.setValue(0.5); assert(v == 0.5); v = 0.25; w.onDataModelSync(); assert(w.getValue() == v); w.setValue(0.2); assert(w.data().toToken() == "0.2"); v = 0; w.setDataFromString("0.8"); assert(w.getValue()==0.8 && w.getValue()==v); } { bool b=false; TextView w; w.attach(ntValue, Update::Value, &b); w.setValue("hello"); assert(b); assert(w.getValue() == "hello"); assert(w.data().toToken() == "\"hello\""); std::string v = "test"; w.attachVariable(v); w.onDataModelSync(); assert(w.getValue() == "test"); w.setDataFromString("\"world\""); assert(w.getValue() == "world"); assert(v == "world"); } // model to string conversion { Label l; TextView tv; Button b; Buttons bs(Rect(), 2, 2); Slider s; Sliders ss(Rect(), 1, 4); Slider2D s2D; NumberDialer nd(1,4,1,-1); std::string strings[] = {"test1", "test2", "test3"}; l.setValue("Hello Label!").name("l"); tv.setValue("Hello TextView!").name("tv"); b.setValue(true).name("b"); bs.setValue(true, 0,1).name("bs"); s.setValue(0.5).name("s"); ss.setValue(0.4, 1).name("ss"); s2D.setValue(0.5, 0).setValue(0.1, 1).name("s2D"); nd.setValue(-0.54941).name("nd"); const View * views[] = {&l, &tv, &b, &bs, &s, &ss, &s2D, &nd}; for(unsigned i=0; i<sizeof(views)/sizeof(View *); ++i){ //const Data& d = views[i]->data(); //printf("%p: %s\n", &d, d.toString().c_str()); //views[i]->model().print(); printf("\n"); } View top; top << l << tv << b << bs << s << ss << s2D << nd; std::string str1, str2; // top.modelToString(str1, "test model"); // printf("%s\n", str1.c_str()); // // l.setValue("changed..."); // top.modelFromString(str1); // top.modelToString(str2); // printf("%s\n", str2.c_str()); // assert(str1 == str2); ModelManager mm; mm.add("l", l); mm.add("tv", tv); mm.add("b", b); mm.add("bs", bs); mm.add("s" , s); mm.add("ss", ss); mm.add("s2D",s2D); mm.add("nd", nd); Data dat(strings, 3); //Data dat(10); //dat.print(); //mm.add("strings", dat); //mm.add("strings", *new Data(strings, 3)); // mm.toToken(str1, "test"); // printf("%s\n", str1.c_str()); // // mm.fromToken(str1); // mm.toToken(str2, "test"); // printf("%s\n", str2.c_str()); std::string snapshotString1 = "[\"test 1\"] = {\n\ l = \"Label 1\",\n\ tv = \"TextView 1\",\n\ b = 0,\n\ bs = {0,0,0,0},\n\ }"; std::string snapshotString2 = "[\"test 2\"] = {\n\ l = \"Label 2\",\n\ tv = \"TextView 2\",\n\ b = 1,\n\ bs = {1,1,1,1},\n\ s = 1,\n\ ss = {1,1,1,1},\n\ s2D = {1,1},\n\ nd = 1,\n\ }"; mm.snapshotsFromString("{" + snapshotString1 + ",\r\n" + snapshotString2 + "}"); // mm.snapshots()["test 1"]["l"].print(); // mm.snapshots()["test 1"]["b"].print(); // mm.snapshots()["test 1"]["bs"].print(); // mm.snapshots()["test 1"]["s"].print(); // mm.snapshots()["test 1"]["ss"].print(); // mm.snapshots()["test 1"]["s2D"].print(); // mm.snapshots()["test 1"]["nd"].print(); // mm.snapshots()["test 2"]["l"].print(); // mm.snapshots()["test 2"]["b"].print(); // mm.snapshots()["test 2"]["bs"].print(); // mm.snapshots()["test 2"]["s"].print(); // mm.snapshots()["test 2"]["ss"].print(); // mm.snapshots()["test 2"]["s2D"].print(); // mm.snapshots()["test 2"]["nd"].print(); // // mm.snapshotsToFile("snapshots.txt"); // // mm.clearSnapshots(); // mm.snapshotsFromFile("snapshots.txt"); // // str1.clear(); // mm.snapshotsToString(str1); // printf("%s\n", str1.c_str()); } // { // std::string str( "a bc ab ca ab" ); // std::string searchString("ab"); // std::string replaceString("hello"); // // std::string::size_type pos = 0; // while((pos = str.find(searchString, pos)) != std::string::npos){ // str.replace(pos++, searchString.size(), replaceString); // } // printf("%s\n", str.c_str()); // } // printf("sizeof(Notifier): %d\n", sizeof(Notifier)); // printf("sizeof(View): %d\n", sizeof(View)); // printf("sizeof(Data): %d\n", sizeof(Data)); // printf("sizeof(Model): %d\n", sizeof(Model)); // printf("sizeof(ModelManager): %d\n", sizeof(ModelManager)); return 0; }
void addModelToSolution(const std::shared_ptr<Model>& model, const Remapper& remapper, ModelManager& solution, Printer& printer) { auto outmodel = createModel(model, remapper); solution.addModel(outmodel); printer.addModel(outmodel); }