void CForceFeedBackSystem::LoadEnvelopes( XmlNodeRef& envelopesNode ) { const int envelopesCount = envelopesNode->getChildCount(); m_envelopes.reserve(envelopesCount); TSamplesBuffer samplesBuffer; const int maxSampleCount = FFSYSTEM_MAX_ENVELOPE_SAMPLES / 2; float readValues[maxSampleCount]; for (int i = 0; i < envelopesCount; ++i) { XmlNodeRef envelopeChildNode = envelopesNode->getChild(i); const char* customEnvelopeName = envelopeChildNode->getAttr("name"); if (!customEnvelopeName || (customEnvelopeName[0] == '\0')) { FORCEFEEDBACK_LOG("Could not load envelope without name (at line %d)", envelopeChildNode->getLine()); continue; } samplesBuffer = envelopeChildNode->haveAttr("name") ? envelopeChildNode->getAttr("samples") : ""; int samplesFound = ParseSampleBuffer(samplesBuffer, &readValues[0], maxSampleCount); if (samplesFound != 0) { SEnvelope customEnvelope; customEnvelope.ResetToDefault(); DistributeSamples(&readValues[0], samplesFound, &customEnvelope.m_envelopeSamples[0], FFSYSTEM_MAX_ENVELOPE_SAMPLES); customEnvelope.m_envelopeId.Set(customEnvelopeName); m_envelopes.push_back(customEnvelope); } else { FORCEFEEDBACK_LOG("Envelope '%s' (at line %d) has not samples, skipping", customEnvelopeName, envelopeChildNode->getLine()); } } std::sort(m_envelopes.begin(), m_envelopes.end()); }
void CForceFeedBackSystem::LoadPatters( XmlNodeRef& patternsNode ) { const int patterCount = patternsNode->getChildCount(); m_patters.reserve(patterCount); TSamplesBuffer samplesBuffer; const int maxSampleCount = FFSYSTEM_MAX_PATTERN_SAMPLES / 2; float readValues[maxSampleCount]; for (int i = 0; i < patterCount; ++i) { XmlNodeRef childPatternNode = patternsNode->getChild(i); const char* customPatternName = childPatternNode->getAttr("name"); if (!customPatternName || (customPatternName[0] == '\0')) { FORCEFEEDBACK_LOG("Could not load pattern without name (at line %d)", childPatternNode->getLine()); continue; } samplesBuffer = childPatternNode->haveAttr("name") ? childPatternNode->getAttr("samples") : ""; int samplesFound = ParseSampleBuffer(samplesBuffer, &readValues[0], maxSampleCount); if (samplesFound != 0) { SPattern customPattern; customPattern.ResetToDefault(); DistributeSamples(&readValues[0], samplesFound, &customPattern.m_patternSamples[0], FFSYSTEM_MAX_PATTERN_SAMPLES); customPattern.m_patternId.Set(customPatternName); m_patters.push_back(customPattern); } else { FORCEFEEDBACK_LOG("Pattern '%s' (at line %d) has not samples, skipping", customPatternName, childPatternNode->getLine()); } } std::sort(m_patters.begin(), m_patters.end()); }
void CVehicleModificationParams::InitModificationElem( XmlNodeRef xmlElem ) { assert( m_pImpl != NULL ); assert( xmlElem != (IXmlNode*)NULL ); bool valid = true; valid &= xmlElem->haveAttr( "idRef" ); valid &= xmlElem->haveAttr( "name" ); valid &= xmlElem->haveAttr( "value" ); if ( ! valid ) { CryLog( "Vehicle modification element at line %i invalid, skipping.", xmlElem->getLine() ); return; } const char* id = xmlElem->getAttr( "idRef" ); const char* attrName = xmlElem->getAttr( "name" ); Implementation::TModificationKey key( id, attrName ); m_pImpl->m_modifications[ key ] = xmlElem; }
SUnlock::SUnlock(XmlNodeRef node, int rank) { m_name[0] = '\0'; m_rank = rank; m_reincarnation = 0; m_unlocked = false; m_type = eUT_Invalid; DesignerWarning(strcmpi(node->getTag(), "unlock") == 0 || strcmpi(node->getTag(), "allow") == 0, "expect tag of unlock or allow at %d", node->getLine()); const char * theName = node->getAttr("name"); const char * theType = node->getAttr("type"); const char * theReincarnationLevel = node->getAttr("reincarnation"); // These pointers should always be valid... if an attribute isn't found, getAttr returns a pointer to an empty string [TF] assert (theName && theType); if (theType && theType[0] != '\0') { m_type = SUnlock::GetUnlockTypeFromName(theType); cry_strcpy(m_name, theName); bool expectName = (m_type == eUT_Loadout || m_type == eUT_Weapon || m_type == eUT_Attachment || m_type == eUT_Playlist || m_type == eUT_CreateCustomClass); bool gotName = (theName[0] != '\0'); if (expectName != gotName && m_type != eUT_Invalid) // If it's invalid, we'll already have displayed a warning... { GameWarning("[PROGRESSION] An unlock of type '%s' %s have a name but XML says name='%s'", theType, expectName ? "should" : "shouldn't", theName); } } else { GameWarning("[PROGRESSION] XML node contains an 'unlock' tag with no type (name='%s')", theName); } if (theReincarnationLevel != NULL && theReincarnationLevel[0] != '\0') { m_reincarnation = atoi(theReincarnationLevel); CPlayerProgression *pPlayerProgression = CPlayerProgression::GetInstance(); DesignerWarning(m_reincarnation > 0 && m_reincarnation < pPlayerProgression->GetMaxReincarnations()+1, "Unlock %s reincarnation parameter is outside of the range 0 - %d", theName, pPlayerProgression->GetMaxReincarnations()+1); } }
void CForceFeedBackSystem::LoadEffects( XmlNodeRef& effectsNode ) { CGameXmlParamReader paramReader(effectsNode); const int effectsCount = paramReader.GetUnfilteredChildCount(); m_effectToIndexMap.reserve(effectsCount); m_effects.reserve(effectsCount); m_effectNames.reserve(effectsCount); for (int i = 0; i < effectsCount; ++i) { XmlNodeRef childEffectNode = paramReader.GetFilteredChildAt(i); if( childEffectNode ) { SEffect newEffect; const int effectDataCount = childEffectNode->getChildCount(); const char* effectName = childEffectNode->getAttr("name"); //Check for invalid name if ((effectName == NULL) || (effectName[0] == '\0')) { FORCEFEEDBACK_LOG("Could not load effect without name (at line %d)", childEffectNode->getLine()); continue; } //Check for duplicates if (m_effectToIndexMap.find(FFBInternalId::GetIdForName(effectName)) != m_effectToIndexMap.end()) { FORCEFEEDBACK_LOG("Effect '%s' does already exists, skipping", effectName); continue; } childEffectNode->getAttr("time", newEffect.time); for (int j = 0; j < effectDataCount; ++j) { XmlNodeRef motorNode = childEffectNode->getChild(j); const char* motorTag = motorNode->getTag(); if (strcmp(motorTag, "MotorAB") == 0) { newEffect.patternA.Set( motorNode->haveAttr("pattern") ? motorNode->getAttr("pattern") : "" ); newEffect.patternB = newEffect.patternA; newEffect.envelopeA.Set( motorNode->haveAttr("envelope") ? motorNode->getAttr("envelope") : "" ); newEffect.envelopeB = newEffect.envelopeA; motorNode->getAttr("frequency", newEffect.frequencyA); newEffect.frequencyB = newEffect.frequencyA; } else if (strcmp(motorTag, "MotorA") == 0) { newEffect.patternA.Set( motorNode->haveAttr("pattern") ? motorNode->getAttr("pattern") : "" ); newEffect.envelopeA.Set( motorNode->haveAttr("envelope") ? motorNode->getAttr("envelope") : "" ); motorNode->getAttr("frequency", newEffect.frequencyA); } else if (strcmp(motorTag, "MotorB") == 0) { newEffect.patternB.Set( motorNode->haveAttr("pattern") ? motorNode->getAttr("pattern") : "" ); newEffect.envelopeB.Set( motorNode->haveAttr("envelope") ? motorNode->getAttr("envelope") : "" ); motorNode->getAttr("frequency", newEffect.frequencyB); } } newEffect.frequencyA = (float)__fsel(-newEffect.frequencyA, 1.0f, newEffect.frequencyA); newEffect.frequencyB = (float)__fsel(-newEffect.frequencyB, 1.0f, newEffect.frequencyB); m_effects.push_back(newEffect); m_effectNames.push_back(effectName); FFBInternalId internalId; internalId.Set(effectName); m_effectToIndexMap.insert(TEffectToIndexMap::value_type(internalId, ((int)m_effects.size() - 1))); } } }
void CMFXLibrary::LoadFromXml( SLoadingEnvironment& loadingEnvironment ) { CryLogAlways("[MFX] Loading FXLib '%s' ...", loadingEnvironment.libraryName.c_str()); INDENT_LOG_DURING_SCOPE(); for (int i = 0; i < loadingEnvironment.libraryParamsNode->getChildCount(); ++i) { XmlNodeRef currentEffectNode = loadingEnvironment.libraryParamsNode->getChild(i); if (!currentEffectNode) continue; TMFXContainerPtr pContainer = MaterialEffectsUtils::CreateContainer(); pContainer->BuildFromXML(currentEffectNode); const TMFXNameId& effectName = pContainer->GetParams().name; const bool effectAdded = AddContainer(effectName, pContainer); if (effectAdded) { loadingEnvironment.AddLibraryContainer(loadingEnvironment.libraryName, pContainer); } else { GameWarning("[MFX] Effect (at line %d) '%s:%s' already present, skipping redefinition!", currentEffectNode->getLine(), loadingEnvironment.libraryName.c_str(), effectName.c_str()); } } }
bool CGameTokenSystem::_InternalLoadLibrary( const char *filename, const char* tag ) { XmlNodeRef root = GetISystem()->LoadXmlFromFile( filename ); if (!root) { GameWarning( _HELP("Unable to load game token database: %s"), filename ); return false; } if (0 != strcmp( tag, root->getTag() )) { GameWarning( _HELP("Not a game tokens library : %s"), filename ); return false; } // GameTokens are (currently) not saved with their full path // we expand it here to LibName.TokenName string libName; { const char *sLibName = root->getAttr("Name"); if (sLibName == 0) { GameWarning( "GameTokensLibrary::LoadLibrary: Unable to find LibName in file '%s'", filename); return false; } libName = sLibName; } // we dont skip already loaded libraries anymore. We need to reload them to be sure that all necessary gametokens are present even if some level has not up-to-date libraries. if (!stl::find(m_libraries, libName)) //return true; m_libraries.push_back(libName); libName+= "."; int numChildren = root->getChildCount(); for (int i=0; i<numChildren; i++) { XmlNodeRef node = root->getChild(i); const char *sName = node->getAttr("Name"); const char *sType = node->getAttr("Type"); const char *sValue = node->getAttr("Value"); const char *sLocalOnly = node->getAttr("LocalOnly"); int localOnly=atoi(sLocalOnly); EFlowDataTypes tokenType = eFDT_Any; if (0 == strcmp(sType,"Int")) tokenType = eFDT_Int; else if (0 == strcmp(sType,"Float")) tokenType = eFDT_Float; else if (0 == strcmp(sType,"EntityId")) tokenType = eFDT_EntityId; else if (0 == strcmp(sType,"Vec3")) tokenType = eFDT_Vec3; else if (0 == strcmp(sType,"String")) tokenType = eFDT_String; else if (0 == strcmp(sType,"Bool")) tokenType = eFDT_Bool; if (tokenType == eFDT_Any) { GameWarning(_HELP("Unknown game token type %s in token %s (%s:%d)"),sType,sName,node->getTag(),node->getLine()); continue; } TFlowInputData initialValue = TFlowInputData(string(sValue)); string fullName (libName); fullName+=sName; IGameToken *pToken = stl::find_in_map(*m_pGameTokensMap,fullName,NULL); if (!pToken) { pToken = SetOrCreateToken( fullName,initialValue ); if (pToken && localOnly) pToken->SetFlags(pToken->GetFlags()|EGAME_TOKEN_LOCALONLY); } } return true; }