/*Save the current objects to the file.*/ HRESULT INTERACTIVE::SPressed() { SCENE::SPressed(); script.ResetPos(); script.FindElem(L"SCENE"); script.IntoElem(); script.FindElem(L"OBJECTS"); script.IntoElem(); while(script.FindElem(L"OBJECT")) script.RemoveElem(); for(std::vector<SCENE_OBJECT>::reverse_iterator it = objects.rbegin(); it != objects.rend(); it++){ script.InsertElem(L"OBJECT", L""); script.SetAttrib(L"name", it->name); script.SetAttrib(L"caption", it->caption); script.SetAttrib(L"sound_source", string2wstring(it->sound_path)); script.SetAttrib(L"caption_sound", string2wstring(it->caption_sound_path)); script.SetAttrib(L"v_count", boost::lexical_cast<std::wstring, int>(it->point_count)); script.SetAttrib(L"finish_scene", boost::lexical_cast<std::wstring, int>(static_cast<int>(it->finish_scene))); script.IntoElem(); for (int i = (it->point_count-1); i >= 0; i--){ script.InsertElem(L"VERTEX", L""); script.SetAttrib(L"x", it->points[i].X); script.SetAttrib(L"y", it->points[i].Y); } script.OutOfElem(); } script.Save(L"rough.xml"); return S_OK; }
static iface::cellml_api::CellMLVariable* findLocalVariable(iface::cellml_api::Model* model,const char* name) { iface::cellml_api::CellMLVariable* v = NULL; // find named variable - in local components only! CVpair cv = splitName(name); RETURN_INTO_OBJREF(components,iface::cellml_api::CellMLComponentSet,model->localComponents()); RETURN_INTO_WSTRING(cname,string2wstring(cv.first.c_str())); RETURN_INTO_OBJREF(component,iface::cellml_api::CellMLComponent,components->getComponent(cname.c_str())); if (!component) { std::cerr << "CellMLModelDefinition::findLocalVariable -- unable to find component: " << cv.first.c_str() << std::endl; return NULL; } RETURN_INTO_OBJREF(variables,iface::cellml_api::CellMLVariableSet,component->variables()); RETURN_INTO_WSTRING(vname,string2wstring(cv.second.c_str())); RETURN_INTO_OBJREF(variable,iface::cellml_api::CellMLVariable,variables->getVariable(vname.c_str())); if (!variable) { std::cerr << "CellMLModelDefinition::findLocalVariable -- unable to find variable: " << cv.first.c_str() << " / " << cv.second.c_str() << std::endl; return NULL; } // get source variable v = variable->sourceVariable(); if (!v) { std::cerr << "CellMLModelDefinition::findLocalVariable -- unable get source variable for variable: " << cv.first.c_str() << " / " << cv.second.c_str() << std::endl; return NULL; } return v; }
ItemAttributes& ItemAttributes::operator=( const std::pair< OPCHANDLE, GroupItemElem >& newItem ) { freeStrings(); os::win32::com::zeroMemory( attributes ); attributes->hServer = newItem.first; attributes->bActive = newItem.second->isActived(); attributes->hClient = newItem.second->getClientHandle(); #if( FRL_CHARACTER == FRL_CHARACTER_UNICODE ) attributes->szItemID = util::duplicateString( newItem.second->getItemID() ); #else attributes->szItemID = util::duplicateString( string2wstring( newItem.second->getItemID() ) ); #endif #if( FRL_CHARACTER == FRL_CHARACTER_UNICODE ) attributes->szAccessPath = util::duplicateString( newItem.second->getAccessPath() ); #else attributes->szAccessPath = util::duplicateString( string2wstring( newItem.second->getAccessPath() ) ); #endif address_space::Tag *item = opcAddressSpace::getInstance().getTag( newItem.second->getItemID() ); attributes->dwAccessRights = item->getAccessRights(); attributes->dwBlobSize = 0; attributes->pBlob = NULL; attributes->vtCanonicalDataType = item->getCanonicalDataType(); attributes->vtRequestedDataType = newItem.second->getReguestDataType(); return *this; }
/* Right click - get info about the object. */ HRESULT INTERACTIVE::RightClick(const int x, const int y) { Gdiplus::PointF hit_position(x - static_cast<Gdiplus::REAL>(video_position.left), y - static_cast<Gdiplus::REAL>(video_position.top)); int i = DetectCollision(hit_position); if(i){ // Play audio hr = audio_media_control->Stop(); std::string source = objects[i-1].caption_sound_path; hr = audio_graph->RenderFile(string2wstring(source).c_str(), NULL); HRLog("IGraphBuilder.RenderFile() - additional audio", hr, false); hr = audio_media_control->Run(); if(hr){ OAFilterState filter_state; hr = video_media_control->GetState(INFINITE, &filter_state); HRLog("IMediaControl.GetState - additional audio play", hr, false); } // Display the caption caption_displayed = true; BMP_mix->Clear(key_color); // Bitmap for video mixing DrawString(hit_position, objects[i-1].caption.c_str()); } DrawOutlines(); BlendText(); return hr; }
void CCharacter::initStatus( CharacterInfo *characterInfo, int characterType ) { m_FullHP = characterInfo[characterType].FullHP; m_HealthPoint = m_FullHP; m_MovingSpeed = characterInfo[characterType].MovingSpeed; m_AttackPower = characterInfo[characterType].AttackPower; m_DefensivePower = characterInfo[characterType].DefensivePower; m_AttackRange = characterInfo[characterType].AttackRange; m_SplashAttackRange = characterInfo[characterType].SplashRange; m_AttackSpeed = characterInfo[characterType].AttackSpeed; m_SplashAttack = characterInfo[characterType].IsSplash; m_Identity = characterInfo[characterType].identity; // m_spritePath = CCharacter::string2wstring(policeInfo[police_type_idx].SpritePath.c_str()); m_typeName = characterInfo[characterType].TypeName; m_FreezingAttack = characterInfo[characterType].IsIceAttack; m_FreezingAttackDuration = characterInfo[characterType].FreezingAttackDuration; for (int type=0 ; type<NUMBER_OF_CHARACTER_STATUS ; ++type) { m_Animation[type] = NNAnimation::Create(); int animationLength = characterInfo[characterType].numberOfAnimationImage[type]; for (int sprite=0; sprite<animationLength ; ++sprite) { m_Animation[type]->AddSpriteNode(const_cast<wchar_t*> ( string2wstring(characterInfo[characterType].animationPath[type][sprite]).c_str() ) ); } m_Animation[type]->SetFrameTimeInSection(CHARACTER_ANIMATION_PLAY_TIME/animationLength,0,animationLength-1); m_Animation[type]->SetLoop(false); m_Animation[type]->SetVisible(false); m_Animation[type]->SetPosition(-((m_Animation[type]->GetSpriteList()[0])->GetSprite()->GetImageWidth()/2), -((m_Animation[type]->GetSpriteList()[0])->GetSprite()->GetImageHeight()/2)); AddChild(m_Animation[type]); } m_Animation[CHARACTER_WALK]->SetVisible(true); m_Animation[CHARACTER_WALK]->SetLoop(true); }
/*! * @if jp * @brief プロセスを起動する * @else * @brief Launching a process * @endif */ int launch_shell(std::string command) { #ifdef UNICODE // std::string -> LPTSTR std::wstring wcommand = string2wstring(command); LPTSTR lpcommand = new TCHAR[wcommand.size() + 1]; _tcscpy(lpcommand, wcommand.c_str()); #else // std::string -> LPTSTR LPTSTR lpcommand = new TCHAR[command.size() + 1]; _tcscpy(lpcommand, command.c_str()); #endif // UNICODE STARTUPINFO si; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); PROCESS_INFORMATION pi; ZeroMemory( &pi, sizeof(pi) ); if(!CreateProcess(NULL, lpcommand, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi) ) { delete lpcommand; return -1; } CloseHandle(pi.hProcess); CloseHandle(pi.hThread); delete lpcommand; return 0; }
std::string getCellMLMetadataAsRDFXMLString(const char* mbrurl) { std::string s; // Get the URL from which to load the model if (!mbrurl) return(s); std::wstring URL = string2wstring(mbrurl); RETURN_INTO_OBJREF(cb, iface::cellml_api::CellMLBootstrap, CreateCellMLBootstrap()); RETURN_INTO_OBJREF(ml, iface::cellml_api::ModelLoader, cb->modelLoader()); // Try and load the CellML model from the URL try { RETURN_INTO_OBJREF(model, iface::cellml_api::Model, ml->loadFromURL(URL.c_str())); RETURN_INTO_OBJREF(rr, iface::cellml_api::RDFRepresentation, model->getRDFRepresentation(L"http://www.cellml.org/RDFXML/string")); if (rr) { DECLARE_QUERY_INTERFACE(rrs,rr,cellml_api::RDFXMLStringRepresentation); std::wstring rdf = rrs->serialisedData(); s = wstring2string(rdf.c_str()); } } catch (...) { std::cerr << "getCellMLMetadataAsRDFXMLString: Error loading model URL: " << mbrurl << std::endl; return(s); } return(s); }
CLSID ServerConnection::getCLSID() { FRL_EXCEPT_GUARD(); CLSID server_clsid = GUID_NULL; #if( FRL_CHARACTER == FRL_CHARACTER_UNICODE ) if( FAILED(CLSIDFromProgID( server_id.c_str(), &server_clsid)) ) { if( UuidFromString( (unsigned short*)server_id.c_str(), &server_clsid) != RPC_S_OK ) FRL_THROW_S_CLASS( NotResolveProgID ); } #else if( FAILED(CLSIDFromProgID( string2wstring( server_id ).c_str(), &server_clsid)) ) { if( UuidFromString( (unsigned char*)server_id.c_str(), &server_clsid) != RPC_S_OK ) FRL_THROW_S_CLASS( NotResolveProgID ); } #endif // FRL_CHARACTER_UNICODE return server_clsid; }
/* Left click - acivates the object clicked on. */ HRESULT INTERACTIVE::LeftClick(const int x, const int y) { Gdiplus::PointF hit_position(x - static_cast<Gdiplus::REAL>(video_position.left), y - static_cast<Gdiplus::REAL>(video_position.top)); int i = DetectCollision(hit_position); if(i){ // Play audio hr = audio_media_control->Stop(); std::string source = objects[i-1].sound_path; hr = audio_graph->RenderFile(string2wstring(source).c_str(), NULL); HRLog("IGraphBuilder.RenderFile() - additional audio", hr, false); hr = audio_media_control->Run(); if(hr){ OAFilterState filter_state; hr = video_media_control->GetState(INFINITE, &filter_state); HRLog("IMediaControl.GetState - additional audio play", hr, false); } } return hr; }
bool CCommandParser::ParseParam(int argc, const char**argv, CParameterList* aParamList) { if (argc < 2) { throw CCommandParser::ECmdLineUnknownOption; } bool bContinue = true; while ((--argc > 0) && bContinue) { ++argv; if (**argv != '-') { continue; } bool err = false; const char* optPtr = *argv; switch (toupper(*++optPtr)) { #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK case 'A': { if (argc <= 1) throw CCommandParser::ECmdLineNoDirArgument; --argc; aParamList->SetResourceFilePath(*(++argv)); break; } #endif //SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK case 'C': { if (argc <= 1) throw CCommandParser::ECmdLineNoDirArgument; --argc; aParamList->SetSystemDrive(*(++argv)); break; } case 'D': { --argc; wchar_t buf[2048]; ConvertMultiByteToWideChar(*++argv,-1, buf, 2048); aParamList->SetSystemDriveLetter(tolower(buf[0])); break; } case 'E': { aParamList->SetFlag(CParameterList::EFlagsDisableZDriveChecksSet); break; } #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK case 'F': { aParamList->SetOriginVerificationStatus(false); break; } #endif case 'H': case '?': { DisplayUsage(); bContinue = false; break; } case 'I': { if (argc <= 1) throw CCommandParser::ECmdLineNoConfigFileArgument; --argc; aParamList->SetConfigFile(*(++argv)); break; } case 'K': { // Last command if (argc == 1) { aParamList->SetSisRegistryVersion(SisRegistry::KRegistryV40string); } else { // Check that the next arg is valid std::string versionStr = *(++argv); if (**argv == '-') { aParamList->SetSisRegistryVersion(SisRegistry::KRegistryV40string); --argv; } else { --argc; aParamList->SetSisRegistryVersion(versionStr); } } break; } case 'L': { if (argc > 1) { --argc; wchar_t buf[2048]; ConvertMultiByteToWideChar(*++argv,-1, buf, 2048); iLogFile = buf; } break; } case 'N': { if (argc <= 1) throw CCommandParser::ECmdLineInvalidLanguage; --argc; aParamList->SetLanguage(static_cast< CSISLanguage::TLanguage >( String2Language( *(++argv) ) )); break; } case 'O': { DisplayOpenSSLCopyright(); bContinue = false; break; } case 'P': { if (!(err = argc <= 1)) { --argc; std::string paramFile = *(++argv); ParseParam(argc, paramFile, aParamList); } break; } case 'R': { if (argc <= 1) throw CCommandParser::ECmdLineNoRomRofsLogsArgument; --argc; aParamList->EmptyRomLogFiles(); #ifdef _MSC_VER FilePtr funtionPtr = aParamList->AddRomLogFile; #else FilePtr funtionPtr = &(aParamList->AddRomLogFile); #endif // _MSC_VER String2List(*aParamList, funtionPtr, *(++argv) ); break; } case 'S': { if (argc <= 1) throw CCommandParser::ECmdLineNoSisArgument; --argc; String2SISFileList(*aParamList, argc, ++argv); break; } case 'T': { if (argc <= 1) throw CCommandParser::ECmdLineNoSisStubPathArgument; --argc; aParamList->SetStubDir(*(++argv)); break; } case 'V': { DisplayVersion(); bContinue = false; break; } case 'W': { --argc; iWarnLevel = String2Warn(*(++argv)); break; } case 'X': { if (argc <= 1) throw CCommandParser::ECmdLineMissingPackageUID; --argc; aParamList->EmptyPkgUids(); #ifdef _MSC_VER FilePtr funtionPtr = (aParamList->AddPkgUid); #else FilePtr funtionPtr = &(aParamList->AddPkgUid); #endif // _MSC_VER String2List(*aParamList, funtionPtr, *(++argv) ); break; } case 'Z': { if (argc <= 1) throw CCommandParser::ECmdLineNoDirArgument; --argc; aParamList->SetZDrive(*(++argv)); break; } default: { LERROR(string2wstring(std::string(optPtr))); throw CCommandParser::ECmdLineUnknownOption; } } if (err) { throw CCommandParser::ECmdLineUnknownOption; } } // Finished parsing all the command line options return !bContinue; }
AVSINLINE const CStringW Encoding::utf82unicode (const CStringA &sLine) { return string2wstring( sLine, CP_UTF8 ); }
AVSINLINE const CStringA Encoding::utf82ansi (const CStringA &sLine) { return wstring2string( string2wstring( sLine, CP_UTF8 ), CP_ACP ); }
AVSINLINE const CStringW Encoding::ansi2unicode (const CStringA &sLine) { return string2wstring( sLine, CP_ACP ); }
bool DVLib::FileExists(const std::string& filename) { return FileExists(string2wstring(filename)); }
PostLoadCommand SPCLoader::Apply(RawFile* file) { if (file->size() < 0x10100) { return KEEP_IT; } char signature[34] = { 0 }; file->GetBytes(0, 33, signature); if (memcmp(signature, "SNES-SPC700 Sound File Data", 27) != 0 || file->GetShort(0x21) != 0x1a1a) { return KEEP_IT; } uint8_t * spcData = new uint8_t[0x10000]; memcpy(spcData, file->buf.data+0x100, 0x10000); VirtFile * spcFile = new VirtFile(spcData, 0x10000, file->GetFileName()); // Parse [ID666](http://vspcplay.raphnet.net/spc_file_format.txt) if available. if (file->GetByte(0x23) == 0x1a) { char s[256]; file->GetBytes(0x2e, 32, s); s[32] = '\0'; spcFile->tag.title = string2wstring(std::string(s)); file->GetBytes(0x4e, 32, s); s[32] = '\0'; spcFile->tag.album = string2wstring(std::string(s)); file->GetBytes(0x7e, 32, s); s[32] = '\0'; spcFile->tag.comment = string2wstring(std::string(s)); if (file->GetByte(0xd2) < 0x30) { // binary format file->GetBytes(0xb0, 32, s); s[32] = '\0'; spcFile->tag.artist = string2wstring(std::string(s)); spcFile->tag.length = (double) (file->GetWord(0xa9) & 0xffffff); } else { // text format file->GetBytes(0xb1, 32, s); s[32] = '\0'; spcFile->tag.artist = string2wstring(std::string(s)); file->GetBytes(0xa9, 3, s); s[3] = '\0'; spcFile->tag.length = strtoul(s, NULL, 10); } } // TODO: Extended ID666 support // Load SPC after parsing tag if (!pRoot->SetupNewRawFile(spcFile)) { delete spcFile; return KEEP_IT; } return DELETE_IT; }
void cMakeMenu::loadFromScript( P_CHAR pc ) { VALIDATEPC(pc); NXWCLIENT ps = pc->getClient(); if( ps==NULL ) return; cScpIterator* iter = Scripts::Create->getNewIterator("SECTION MAKEMENU %i", section); if (iter==NULL) return; std::vector<std::string> names; //name std::vector<std::string> models; //models this->mat[0].number = ( mat[0].id!=0 )? pc->CountItems( mat[0].id, mat[0].color ) : 0; this->mat[1].number = ( mat[1].id!=0 )? pc->CountItems( mat[1].id, mat[1].color ) : 0; //da passare a checkReq PDPD cMakeItem* imk = NULL; pc->making=skill; oldmenu->style=MENUTYPE_ICONLIST; /* makemenu menu SECTION MAKEMENU 1 { Blacksmithing 1416 Armor RESOURCE 10 SKILL 500 MAKEMENU 3 13BA Weapons RESOURCE 3 SKILL 100 MAKEMENU 4 1BC3 Shields RESOURCE 8 SKILL 250 MAKEMENU 2 09ed Misc RESOURCE 6 SKILL 150 MAKEMENU 105 } */ /* makemenu item SECTION MAKEMENU 2002 { Golden Ring Mail 13F2 Gloves RESOURCE 10 SKILL 338 ADDITEM $item_golden_ringmail_gloves 13EF Sleeves RESOURCE 14 SKILL 385 ADDITEM $item_golden_ringmail_sleeves 13F1 Leggings RESOURCE 16 SKILL 408 ADDITEM $item_golden_ringmail_leggings 13ED Tunic RESOURCE 18 SKILL 432 ADDITEM $item_golden_ringmail_tunic } */ enum MakeParamType { MAKE_NEED_NAME = 0, //Blacksmithing MAKE_NEED_INFO, //1416 Armor MAKE_NEED_RESOURCE, //RESOURCE 10 MAKE_NEED_SKILL, //SKILL 500 MAKE_NEED_MENUORITEM, //MAKEMENU 3 or ADDITEM $item_golden_ringmail_tunic }; MakeParamType type = MAKE_NEED_NAME; bool error=false; bool canSee = true; int item = INVALID; int loopexit=0; do { std::string lha; std::string rha; iter->parseLine(lha, rha); if( lha[0]=='{' ) continue; if( lha[0]=='}' ) break; switch( type ) { case MAKE_NEED_NAME: //Blacksmithing string2wstring( lha, oldmenu->title ); type = MAKE_NEED_INFO; break; case MAKE_NEED_INFO: { //1416 Armor item++; names.push_back( rha ); models.push_back( lha ); type = MAKE_NEED_RESOURCE; break; } case MAKE_NEED_RESOURCE: //RESOURCE 10 if( lha!="RESOURCE" ) { if ( item > INVALID ) //Luxor LogWarning("create.xss, MAKEMENU %i: Expected 'RESOURCE <num>' after '%s'!", section, names[item].c_str() ); error=true; } else { int needs = str2num(rha); imk = new cMakeItem(); imk->skillToCheck=this->skill; imk->reqitems[0].id=mat[0].id; imk->reqitems[0].color=mat[0].color; imk->reqitems[0].number=needs; imk->reqitems[1].id=mat[1].id; imk->reqitems[1].color=mat[1].color; imk->reqitems[1].number=needs; type=MAKE_NEED_SKILL; } break; case MAKE_NEED_SKILL: //SKILL 500 if( lha!="SKILL" ) { LogWarning("create.xss, MAKEMENU %i: Expected 'SKILL <num>' after RESOURCE !", section ); error=true; } else { imk->minskill=str2num(rha); imk->maxskill=imk->minskill*SrvParms->skilllevel; // by Magius(CHE) if( imk->maxskill<200 ) imk->maxskill=200; if( !imk->checkReq( pc, true, &this->mat[0] ) ) { safedelete( imk ); item--; names.pop_back(); models.pop_back(); canSee = false; } else { makeItems.push_back( imk ); std::wstring w; char b[TEMP_STR_SIZE]; if( mat[0].id!=0 ) { sprintf( b, "%s %s - [%d/%d.%d]", models[item].c_str(), names[item].c_str(), imk->reqitems[0].number, imk->minskill/10, imk->minskill%10 ); } else { sprintf( b, "%s %s", models[item].c_str(), names[item].c_str() ); } string2wstring( std::string( b ), w ); oldmenu->addMenuItem( 0, item, w ); type=MAKE_NEED_MENUORITEM; canSee = true; } type=MAKE_NEED_MENUORITEM; } break; case MAKE_NEED_MENUORITEM: //MAKEMENU 3 or ADDITEM $item_golden_ringmail_tunic if( ( lha=="MAKEMENU" ) || ( lha=="ADDITEM" ) ) { if( canSee ) imk->command = new cScriptCommand( lha, rha ); type = MAKE_NEED_INFO; } else { LogWarning("create.xss, MAKEMENU %i: Expected'MAKEMENU or ADDITEM after 'SKILL %i'!", section, imk->minskill ); error=true; } break; } } while( !error && (++loopexit < MAXLOOPS) ); if( item<=0 ) { ps->sysmsg( TRANSLATE("You aren't skilled enough to make anything with what you have.") ); } safedelete(iter); if( error ) { ConOut( "[ERROR] on cration of makemenu %d\n", section ); return; } }
void cAddMenu::loadFromScript( P_CHAR pc ) { VALIDATEPC(pc); int nOpt = 0; bool bIcons = false; bool bNotDecided = true; cScpIterator* iter = Scripts::Menus->getNewIterator("SECTION MENU %d", section); if(iter == NULL) { // build a fake menu :] oldmenu->setParameters(1, 1); oldmenu->title = L"Menu Error, section not found"; oldmenu->style = MENUTYPE_PAPER; std::wstring ws; string2wstring( std::string("Close this one here"), ws ); oldmenu->addMenuItem( 0, 0, ws ); commands.push_back( cScriptCommand( std::string("NOP"), std::string(" ") ) ); return; } cScpEntry* entry = iter->getEntry(); if (entry->getFullLine().c_str()[0]=='{') entry = iter->getEntry(); while (entry->getFullLine().c_str()[0]!='}') { entry = iter->getEntry(); if (entry->getFullLine().c_str()[0]!='}') { if( (bNotDecided)&&(entry->getFullLine().c_str()[0]!='<') ) bIcons = true; bNotDecided = false; entry = iter->getEntry(); nOpt++; } } iter->rewind(); entry = iter->getEntry(); if (entry->getFullLine().c_str()[0]=='{') entry = iter->getEntry(); if (!bIcons) { oldmenu->setParameters(10,(nOpt/10)+1); oldmenu->style = MENUTYPE_STONE; } else { oldmenu->style = MENUTYPE_ICONLIST; } string2wstring( entry->getFullLine(), oldmenu->title ); nOpt = 0; while (entry->getFullLine().c_str()[0]!='}') { entry = iter->getEntry(); if (entry->getFullLine().c_str()[0]!='}') { cScpEntry* entry2 = iter->getEntry(); std::wstring w; if (!bIcons) string2wstring( cleanString( entry->getFullLine() ), w ); else string2wstring( entry->getFullLine(), w); oldmenu->addMenuItem( nOpt/10, nOpt%10, w ); commands.push_back( cScriptCommand( entry2->getParam1(), entry2->getParam2() ) ); nOpt++; } } safedelete(iter); }
CellMLModelDefinition::CellMLModelDefinition(const char* url) : mURL(url) { //mCompileCommand = "gcc -fPIC -O3 -shared -x c -o"; mCompileCommand = "gcc -fPIC -g -shared -x c -o"; mTmpDirExists = false; mCodeFileExists = false; mDsoFileExists = false; mSaveTempFiles = false; mInstantiated = false; nBound = -1; nRates = -1; nAlgebraic = -1; nConstants = -1; mNumberOfWantedVariables = 0; mNumberOfKnownVariables = 0; mNumberOfIndependentVariables = 0; mStateCounter = 0; mIntermediateCounter = 0; mParameterCounter = 0; mModel = NULL; mCodeInformation = NULL; mAnnotations = NULL; std::cout << "Creating CellMLModelDefinition from the URL: " << url << std::endl; if (! mURL.empty()) { //std::cout << "Have a valid simulation description." << std::endl; //std::cout << " CellML model URI: " << mURL.c_str() << std::endl; RETURN_INTO_WSTRING(URL,string2wstring(mURL.c_str())); RETURN_INTO_OBJREF(cb,iface::cellml_api::CellMLBootstrap, CreateCellMLBootstrap()); RETURN_INTO_OBJREF(ml,iface::cellml_api::ModelLoader,cb->modelLoader()); iface::cellml_api::Model* model = (iface::cellml_api::Model*)NULL; try { model = ml->loadFromURL(URL.c_str()); model->fullyInstantiateImports(); mModel = static_cast<void*>(model); // create the annotation set RETURN_INTO_OBJREF(ats,iface::cellml_services::AnnotationToolService,CreateAnnotationToolService()); iface::cellml_services::AnnotationSet* as = ats->createAnnotationSet(); mAnnotations = static_cast<void*>(as); // make sure we can generate code and get the initial code information RETURN_INTO_OBJREF(cgb,iface::cellml_services::CodeGeneratorBootstrap, CreateCodeGeneratorBootstrap()); RETURN_INTO_OBJREF(cg,iface::cellml_services::CodeGenerator, cgb->createCodeGenerator()); try { RETURN_INTO_OBJREF(cci,iface::cellml_services::CodeInformation, cg->generateCode(model)); // need to keep a handle on the code information cci->add_ref(); mCodeInformation = static_cast<void*>(cci); // and add all state variables as wanted and the variable of integration as known RETURN_INTO_OBJREF(cti,iface::cellml_services::ComputationTargetIterator,cci->iterateTargets()); while(1) { RETURN_INTO_OBJREF(ct,iface::cellml_services::ComputationTarget,cti->nextComputationTarget()); if (ct == NULL) break; if (ct->type() == iface::cellml_services::STATE_VARIABLE) { as->setStringAnnotation(ct->variable(),L"flag",L"STATE"); as->setStringAnnotation(ct->variable(),L"array",L"OC_STATE"); as->setStringAnnotation(ct->variable(),L"array_index",formatNumber(mStateCounter).c_str()); mStateCounter++; } else if (ct->type() == iface::cellml_services::VARIABLE_OF_INTEGRATION) { as->setStringAnnotation(ct->variable(),L"flag",L"INDEPENDENT"); mNumberOfIndependentVariables++; } else if (ct->degree() > 0) { //as->setStringAnnotation(ct->variable(),L"flag-degree",L"WANTED"); //mNumberOfWantedVariables++; } } } catch (...) { std::wcerr << L"Error generating the code information for the model" << std::endl; mCodeInformation = static_cast<void*>(NULL); } } catch (...) { std::wcerr << L"Error loading model URL: " << URL.c_str() << std::endl; mModel = static_cast<void*>(NULL); } } }
void XApp::init() { //// Basic initialization if (initialized) return; initialized = true; if (!ovrRendering) ovrMirror = false; if (ovrRendering) vr.init(); if (appName.length() == 0) { // no app name specified - just use first one from iterator auto it = appMap.begin(); XAppBase *a = it->second; if (a != nullptr) { appName = it->first; Log("WARNING: xapp not specified, using this app: " << appName.c_str() << endl); } } //assert(appName.length() > 0); app = getApp(appName); if (app != nullptr) { //Log("initializing " << appName.c_str() << "\n"); SetWindowText(getHWND(), string2wstring(app->getWindowTitle())); } else { Log("ERROR: xapp not available " << appName.c_str() << endl); // throw assertion error in debug mode assert(app != nullptr); } #ifdef _DEBUG // Enable the D3D12 debug layer. { ComPtr<ID3D12Debug> debugController; if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debugController)))) { debugController->EnableDebugLayer(); } HRESULT getAnalysis = DXGIGetDebugInterface1(0, __uuidof(pGraphicsAnalysis), reinterpret_cast<void**>(&pGraphicsAnalysis)); } #endif //// Viewport and Scissor /* D3D12_RECT rect; if (GetWindowRect(getHWND(), &rect)) { int width = rect.right - rect.left; int height = rect.bottom - rect.top; viewport.MinDepth = 0.0f; viewport.TopLeftX = 0.0f; viewport.TopLeftY = 0.0f; viewport.Width = static_cast<float>(width); viewport.Height = static_cast<float>(height); viewport.MaxDepth = 1.0f; scissorRect.left = 0; scissorRect.top = 0; scissorRect.right = static_cast<LONG>(width); scissorRect.bottom = static_cast<LONG>(height); vr.adaptViews(viewport, scissorRect); } */ //// Pipeline ComPtr<IDXGIFactory4> factory; ThrowIfFailed(CreateDXGIFactory2(0 #ifdef _DEBUG | DXGI_CREATE_FACTORY_DEBUG #endif , IID_PPV_ARGS(&factory))); if (warp) { ComPtr<IDXGIAdapter> warpAdapter; ThrowIfFailed(factory->EnumWarpAdapter(IID_PPV_ARGS(&warpAdapter))); ThrowIfFailed(D3D12CreateDevice( warpAdapter.Get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device) )); } else { ThrowIfFailed(D3D12CreateDevice( nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device) )); } // disable auto alt-enter fullscreen switch (does leave an unresponsive window during debug sessions) ThrowIfFailed(factory->MakeWindowAssociation(getHWND(), DXGI_MWA_NO_ALT_ENTER)); //IDXGIFactory4 *parentFactoryPtr = nullptr; //if (SUCCEEDED(swapChain->GetParent(__uuidof(IDXGIFactory4), (void **)&parentFactoryPtr))) { // parentFactoryPtr->MakeWindowAssociation(getHWND(), DXGI_MWA_NO_ALT_ENTER); // parentFactoryPtr->Release(); //} // Describe and create the command queue. D3D12_COMMAND_QUEUE_DESC queueDesc = {}; queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE; queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT; ThrowIfFailed(device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&commandQueue))); commandQueue->SetName(L"commandQueue_xapp"); calcBackbufferSizeAndAspectRatio(); camera.aspectRatio = aspectRatio; if (ovrRendering) { camera.aspectRatio /= 2.0f; } camera.projectionTransform(); // Describe the swap chain. DXGI_SWAP_CHAIN_DESC swapChainDesc = {}; swapChainDesc.BufferCount = FrameCount; swapChainDesc.BufferDesc.Width = backbufferWidth; swapChainDesc.BufferDesc.Height = backbufferHeight; swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; swapChainDesc.OutputWindow = getHWND(); swapChainDesc.SampleDesc.Count = 1; swapChainDesc.Windowed = TRUE; ComPtr<IDXGISwapChain> swapChain0; // we cannot use create IDXGISwapChain3 directly - create IDXGISwapChain, then call As() to map to IDXGISwapChain3 ThrowIfFailed(factory->CreateSwapChain( commandQueue.Get(), // Swap chain needs the queue so that it can force a flush on it. &swapChainDesc, &swapChain0 )); ThrowIfFailed(swapChain0.As(&swapChain)); //swapChain = nullptr; frameIndex = xapp().swapChain->GetCurrentBackBufferIndex(); if (ovrRendering) { vr.initD3D(); } // Create descriptor heaps. { // Describe and create a render target view (RTV) descriptor heap. D3D12_DESCRIPTOR_HEAP_DESC rtvHeapDesc = {}; rtvHeapDesc.NumDescriptors = FrameCount; rtvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV; rtvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE; ThrowIfFailed(device->CreateDescriptorHeap(&rtvHeapDesc, IID_PPV_ARGS(&rtvHeap))); rtvHeap->SetName(L"rtvHeap_xapp"); rtvDescriptorSize = device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV); } // Create frame resources. { CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(rtvHeap->GetCPUDescriptorHandleForHeapStart()); // Create a RTV for each frame. for (UINT n = 0; n < FrameCount; n++) { ThrowIfFailed(swapChain->GetBuffer(n, IID_PPV_ARGS(&renderTargets[n]))); device->CreateRenderTargetView(renderTargets[n].Get(), nullptr, rtvHandle); wstringstream s; s << L"renderTarget_xapp[" << n << "]"; renderTargets[n]->SetName(s.str().c_str()); rtvHandle.Offset(1, rtvDescriptorSize); //ThrowIfFailed(device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&commandAllocators[n]))); // Describe and create a depth stencil view (DSV) descriptor heap. D3D12_DESCRIPTOR_HEAP_DESC dsvHeapDesc = {}; dsvHeapDesc.NumDescriptors = 1; dsvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV; dsvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE; ThrowIfFailed(device->CreateDescriptorHeap(&dsvHeapDesc, IID_PPV_ARGS(&dsvHeaps[n]))); } // Create the depth stencil view for each frame for (UINT n = 0; n < FrameCount; n++) { D3D12_DEPTH_STENCIL_VIEW_DESC depthStencilDesc = {}; depthStencilDesc.Format = DXGI_FORMAT_D32_FLOAT; depthStencilDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D; depthStencilDesc.Flags = D3D12_DSV_FLAG_NONE; D3D12_CLEAR_VALUE depthOptimizedClearValue = {}; depthOptimizedClearValue.Format = DXGI_FORMAT_D32_FLOAT; depthOptimizedClearValue.DepthStencil.Depth = 1.0f; depthOptimizedClearValue.DepthStencil.Stencil = 0; ThrowIfFailed(device->CreateCommittedResource( &CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE, &CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_D32_FLOAT, backbufferWidth, backbufferHeight, 1, 0, 1, 0, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL), D3D12_RESOURCE_STATE_DEPTH_WRITE, &depthOptimizedClearValue, IID_PPV_ARGS(&depthStencils[n]) )); //NAME_D3D12_OBJECT(m_depthStencil); device->CreateDepthStencilView(depthStencils[n].Get(), &depthStencilDesc, dsvHeaps[n]->GetCPUDescriptorHandleForHeapStart()); wstringstream s; s << L"depthStencil_xapp[" << n << "]"; depthStencils[n]->SetName(s.str().c_str()); } } //// Assets // Create an empty root signature. { CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc; rootSignatureDesc.Init(0, nullptr, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT); ComPtr<ID3DBlob> signature; ComPtr<ID3DBlob> error; ThrowIfFailed(D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error)); ThrowIfFailed(device->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&rootSignature))); } // 11 on 12 device support UINT d3d11DeviceFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT; #if defined(_DEBUG) if (disableDX11Debug == false) { d3d11DeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; } #endif ThrowIfFailed(D3D11On12CreateDevice( device.Get(), d3d11DeviceFlags, nullptr, 0, reinterpret_cast<IUnknown**>(commandQueue.GetAddressOf()), 1, 0, &d3d11Device, &d3d11DeviceContext, nullptr )); // Query the 11On12 device from the 11 device. ThrowIfFailed(d3d11Device.As(&d3d11On12Device)); // feature levels: we need DX 10.1 as minimum D3D_FEATURE_LEVEL out_level; array<D3D_FEATURE_LEVEL, 3> levels{ { D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1 } }; //ID3D11DeviceContext* context = nullptr; UINT flags = disableDX11Debug ? 0 : D3D11_CREATE_DEVICE_DEBUG; ThrowIfFailed(D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, flags, &levels[0], (UINT)levels.size(), D3D11_SDK_VERSION, &reald3d11Device, &out_level, &reald3d11DeviceContext)); // 11 on 12 end camera.ovrCamera = true; if (!ovrRendering) camera.ovrCamera = false; gametime.init(1); // init to real time camera.setSpeed(1.0f); initPakFiles(); app->init(); app->update(); }