bool EntityLODComponent::ParseXMLNode(TiXmlElement *pLODNode)
{
  if (!pLODNode)
    return false;

  // first count the number of elements
  TiXmlElement* pElement;

  // load constraints
  TiXmlNode *pFirstNode = pLODNode->FirstChild("LODLevel");
  if (!pFirstNode)
    return false;

  int iCount = 0;
  // iterate through all sub-nodes and count them
	for (pElement=pFirstNode->ToElement(); pElement!=NULL; pElement=pElement->NextSiblingElement("LODLevel"))
	  iCount++;
  AllocateLevels(iCount);

  // iterate again and parse
  iCount = 0;
  for (pElement=pFirstNode->ToElement(); pElement!=NULL; pElement=pElement->NextSiblingElement("LODLevel"))
    GetLevelInfo(iCount++).ParseXMLNode(pElement);


  return true;
}
示例#2
0
bool COptions::LoadLevel( const char *filename )
{
    //-----------------------------------
    // Allocate data and name for 1 level
    //-----------------------------------

    AllocateLevels(1);
    
    //------------------------------------------------------
    // Load all the level files detected earlier
    //------------------------------------------------------
    
    bool ErrorOccurred = false;    
    
    // Open the existing level file for reading
    ifstream in;
    in.open( filename, ios_base::in );

    // If it failed
    if (!in.is_open())
    {
        cerr << "Loading level file " << filename << " failed." << endl;
        // Stop loading levels
        return false;
    }

    // This is the first line for the level files beginning with version 2 (therefore "V2plus")
    string headerV2plus( "; Bombermaaan level file version=" );

    string s;
    getline( in, s );
    int LevelVersion;

    // When header string is found at the beginning of the string, find() returns 0 (offset 0)
    if ( s.find( headerV2plus ) == 0 ) {
        // We can look for the level version now
        LevelVersion = atoi( s.substr( headerV2plus.length() ).c_str() );
    }
    else
    {
        LevelVersion = 1;
    }
    
    switch ( LevelVersion ) {

        case 1:
            if (!LoadLevel_Version1( in, 0 ) ) {
                ErrorOccurred = true;
            }
            break;

        case 2:
            if (!LoadLevel_Version2( filename, 0 ) ) {
                ErrorOccurred = true;
            }
            break;

        default:
            printf ("Options         => !!! Unsupported version of level file %s.", filename);
            ErrorOccurred = true;
            break;

    }

	// Close the level file
    in.close();
    
    unsigned int sumOfMaxItems;

    // too many items?
    if (!ErrorOccurred && !CheckMaxNumberOfItems( 0, &sumOfMaxItems ))
    {
        // Log there is a problem
        cerr << "!!! Level file is incorrect (Too many items: " << sumOfMaxItems << " of " << MAX_ITEMS << " allowed)." << endl;

        // Stop loading levels
        ErrorOccurred = true;
    }

    // If we had to stop then there is a problem.
    if (ErrorOccurred)
        return false;

    // Everything went right
    return true;
}