Exemple #1
0
XmlNodeRef XmlParser::parse(behaviac::IFile* file, const char* rootNodeName, const char* suffix, bool handleError)
{
    BEHAVIAC_UNUSED_VAR(suffix);
    BEHAVIAC_UNUSED_VAR(handleError);

    m_errorString.clear();
    XmlParserImp xml;

    if (file)
    {
        int iSize = (int)file->GetSize() - (int)file->Seek(0, behaviac::CFileSystem::ESeekMoveMode_Cur);

        if (iSize != 0)
        {
            static const int32_t ReadBlockSize = 64 * 1024;
            char* buf = (char*)BEHAVIAC_MALLOC_WITHTAG(ReadBlockSize, "XML");
            XmlNodeRef ref;

            for (int32_t i = 0; i <= iSize / (ReadBlockSize); ++i)
            {
                int32_t bufSize = file->Read(buf, ReadBlockSize);
                {
                    buf[bufSize] = '\0';
                    ref = xml.parse(buf, bufSize, rootNodeName, m_errorString, i == iSize / (ReadBlockSize));
                }
            }

            BEHAVIAC_FREE(buf);

            if (handleError && !m_errorString.empty())
            {
                BEHAVIAC_LOGWARNING("Error while parsing file\n\n%s", m_errorString.c_str());
            }

            return ref;

        }
        else
        {
            return XmlNodeRef();
        }
    }
    else
    {
        BEHAVIAC_ASSERT(0, "XmlParse(behaviac::IFile*) - Invalid file\n");
        return XmlNodeRef();
    }
}
XmlNodeRef CVehicleModificationParams::GetModificationNode( const char* nodeId, const char* attrName ) const
{
	assert( nodeId != NULL );
	assert( attrName != NULL );

	if ( m_pImpl == NULL )
	{
		return XmlNodeRef();
	}

	Implementation::TModificationKey key( nodeId, attrName );
	Implementation::TModificationMap::const_iterator cit = m_pImpl->m_modifications.find( key );
	bool modificationFound = ( cit != m_pImpl->m_modifications.end() );
	if ( ! modificationFound )
	{
		return XmlNodeRef();
	}

	return cit->second;
}
Exemple #3
0
//! Parse xml file.
XmlNodeRef XmlParser::parse( const String& fileName )
{
	m_errorString = "";
	XmlParserImp xml;
	//std::vector<char> buf;
	//String buf;
	char *buf;

	FILE *file;
#if _MSC_VER<=1200
	file = fopen( fileName.c_str(),"rb" );
	if (file) {
#else
	if (!fopen_s(&file, fileName.c_str(),"rb" )) {
#endif
		fseek( file,0,SEEK_END );
		int fileSize = ftell(file);
		fseek( file,0,SEEK_SET );

		int buffersize = fileSize;
		buf=new char[buffersize ];

		fread( buf,fileSize,1,file );
//		buf.resize( fileSize );
//		fread( buf.begin(),fileSize,1,file );
		fclose(file);

		XmlNodeRef nodeR =xml.parse( buf,buffersize ,m_errorString );
		
		delete buf;

		return nodeR;
			
	} else {
		return XmlNodeRef();
	}
}
	
//! Parse xml from memory buffer.
XmlNodeRef XmlParser::parse( const std::vector<char, hb::allocator<char> > &buffer )
{
	m_errorString = "";
	XmlParserImp xml;
	
	//return xml.parse( buffer,m_errorString );

	assert(0);
		XmlNodeRef nodeR;
		return nodeR;
	
};
XmlNodeRef CVehicleModificationParams::FindModificationNodeByName( const char* name, XmlNodeRef xmlModificationsGroup )
{
	assert( name != NULL );
	assert( xmlModificationsGroup );

	int numNodes = xmlModificationsGroup->getChildCount();
	for ( int i = 0; i < numNodes; i++ )
	{
		XmlNodeRef xmlModification = xmlModificationsGroup->getChild( i );
		const char* modificationName = xmlModification->getAttr( "name" );
		if ( modificationName!=0 && ( strcmpi( name, modificationName ) == 0 ) )
		{
			return xmlModification;
		}
	}

	return XmlNodeRef();
}
Exemple #5
0
XmlNodeRef XmlParser::parse(const char* fileName, const char* rootNodeName, const char* suffix)
{
    m_errorString.clear();
    behaviac::IFile* file = behaviac::CFileManager::GetInstance()->FileOpen(fileName, behaviac::CFileSystem::EOpenAccess_Read);

    if (file)
    {
        XmlNodeRef xml = this->parse(file, rootNodeName, suffix, false);
        behaviac::CFileManager::GetInstance()->FileClose(file);

        if (!m_errorString.empty())
        {
            BEHAVIAC_LOGWARNING("Error while parsing file : %s\n\n%s", fileName, m_errorString.c_str());
        }

        return xml;

    }
    else
    {
        BEHAVIAC_ASSERT(0, "Cannot open XML file : %s\n", fileName);
        return XmlNodeRef();
    }
}
Exemple #6
0
 virtual XmlNodeRef GetCreationNode(){ return XmlNodeRef(0); }  
Exemple #7
0
void CUIHUD3D::SpawnHudEntities()
{
    RemoveHudEntities();

    if (gEnv->IsEditor() && gEnv->IsEditing())
        return;

    const char* hudprefab = NULL;
    IGameRules* pGameRules = gEnv->pGame->GetIGameFramework()->GetIGameRulesSystem()->GetCurrentGameRules();
    if (pGameRules)
    {
        IScriptTable* pTable = pGameRules->GetEntity()->GetScriptTable();
        if (pTable)
        {
            if (!pTable->GetValue("hud_prefab", hudprefab))
                hudprefab = NULL;
        }
    }
    hudprefab = hudprefab ? hudprefab : HUD3D_PREFAB_LIB;

    XmlNodeRef node = gEnv->pSystem->LoadXmlFromFile(hudprefab);
    if (node)
    {
        // get the prefab with the name defined in HUD3D_PREFAB_NAME
        XmlNodeRef prefab = NULL;
        for (int i = 0; i < node->getChildCount(); ++i)
        {
            const char* name = node->getChild(i)->getAttr("Name");
            if (name && strcmp(name, HUD3D_PREFAB_NAME) == 0)
            {
                prefab = node->getChild(i);
                prefab = prefab ? prefab->findChild("Objects") : XmlNodeRef();
                break;
            }
        }

        if (prefab)
        {
            // get the PIVOT entity and collect childs
            XmlNodeRef pivotNode = NULL;
            std::vector<XmlNodeRef> childs;
            const int count = prefab->getChildCount();
            childs.reserve(count-1);

            for (int i = 0; i < count; ++i)
            {
                const char* name = prefab->getChild(i)->getAttr("Name");
                if (strcmp("PIVOT", name) == 0)
                {
                    assert(pivotNode == NULL);
                    pivotNode = prefab->getChild(i);
                }
                else
                {
                    childs.push_back(prefab->getChild(i));
                }
            }

            if (pivotNode)
            {
                // spawn pivot entity
                IEntityClass* pEntClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass( pivotNode->getAttr("EntityClass") );
                if (pEntClass)
                {
                    SEntitySpawnParams params;
                    params.nFlags = ENTITY_FLAG_CLIENT_ONLY;
                    params.pClass = pEntClass;
                    m_pHUDRootEntity = gEnv->pEntitySystem->SpawnEntity(params);
                }

                if (!m_pHUDRootEntity) return;

                m_HUDRootEntityId = m_pHUDRootEntity->GetId();

                // spawn the childs and link to the pivot enity
                for (std::vector<XmlNodeRef>::iterator it = childs.begin(); it != childs.end(); ++it)
                {
                    XmlNodeRef child = *it;
                    pEntClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass( child->getAttr("EntityClass") );
                    if (pEntClass)
                    {
                        const char* material = child->getAttr("Material");
                        Vec3 pos;
                        Vec3 scale;
                        Quat rot;
                        child->getAttr("Pos", pos);
                        child->getAttr("Rotate", rot);
                        child->getAttr("Scale", scale);

                        SEntitySpawnParams params;
                        params.nFlags = ENTITY_FLAG_CLIENT_ONLY;
                        params.pClass = pEntClass;
                        params.vPosition = pos;
                        params.qRotation = rot;
                        params.vScale = scale;
                        IEntity* pEntity = gEnv->pEntitySystem->SpawnEntity(params);
                        if (pEntity)
                        {
                            IScriptTable* pScriptTable = pEntity->GetScriptTable();
                            if (pScriptTable)
                            {
                                SmartScriptTable probs;
                                pScriptTable->GetValue("Properties", probs);

                                XmlNodeRef properties = child->findChild("Properties");
                                if (probs && properties)
                                {
                                    for (int k = 0; k < properties->getNumAttributes(); ++k)
                                    {
                                        const char* sKey;
                                        const char* sVal;
                                        properties->getAttributeByIndex(k, &sKey, &sVal);
                                        probs->SetValue(sKey, sVal);
                                    }
                                }
                                Script::CallMethod(pScriptTable,"OnPropertyChange");
                            }

                            if (material)
                            {
                                IMaterial* pMat = gEnv->p3DEngine->GetMaterialManager()->LoadMaterial(material);
                                if (pMat)
                                    pEntity->SetMaterial(pMat);
                            }
                            m_pHUDRootEntity->AttachChild(pEntity);
                            m_HUDEnties.push_back( pEntity->GetId() );
                        }
                    }
                }
            }
        }
    }

    OnVisCVarChange( NULL );
}
void CXmlSerializedObject::Reset()
{
	m_XmlNode = XmlNodeRef();
}
SSpreadParams::SSpreadParams()
{
	Reset(XmlNodeRef(NULL));
}
SProceduralRecoilParams::SProceduralRecoilParams()
{
	Reset(XmlNodeRef(NULL));
}
SRecoilParams::SRecoilParams()
{
	Reset(XmlNodeRef(NULL));
}
Exemple #12
0
void CAntiCheatManager::Update(float dt)
{
	while (!m_queuedFlagActivity.empty())
	{
		if (m_mutex.TryLock())
		{
			if (!m_queuedFlagActivity.empty())
			{
				// Get a copy of the item off the queue
				SQueuedFlagActivity item = m_queuedFlagActivity.front();
				m_queuedFlagActivity.pop();
				// Unlock the queue
				m_mutex.Unlock();
				// And process it
				const char* sMessage = NULL;
				if (!item.message.empty())
				{
					sMessage = item.message.c_str();
				}
				ProcessFlagActivity(item.type, item.channelId, item.params, item.numParams, sMessage, XmlNodeRef());
			}
			else
			{
				// Queue no longer has items in it? Shouldn't reach this point really because this is the only place items are popped off.
				assert(false);
				m_mutex.Unlock();
			}
		}
		else
		{
			// Try lock failed, let's do it next frame
			break;
		}
	}

	if(!m_DelayedKickData.empty())
		HandleDelayedKicks(dt);

}