Ejemplo n.º 1
0
void CopyXMLNode(csRef<iDocumentNode> source, csRef<iDocumentNode> target, int mode)
{
    if (mode == 0)
    {
        target->RemoveNodes();
        target->RemoveAttributes();
    }
    
    // copy nodes
    csRef<iDocumentNodeIterator> nodeIter = source->GetNodes();
    while (nodeIter->HasNext())
    {
        csRef<iDocumentNode> child = nodeIter->Next();
        csRef<iDocumentNode> targetChild = target->GetNode(child->GetValue());
        if (targetChild==NULL || mode==3)  // Mode 3 means don't merge tags but just insert multiples, so we create a new one here every time
        {
            targetChild = target->CreateNodeBefore(child->GetType());
            if (targetChild == NULL)
                assert(!"failed to create XML node, you are probably using wrong XML parser (xmlread instead of xmltiny)");
            targetChild->SetValue(child->GetValue());
        }
        CopyXMLNode(child, targetChild, mode);
    }
    
    // copy attributes
    csRef <iDocumentAttributeIterator> attrIter = source->GetAttributes();
    while (attrIter->HasNext())
    {
        csRef<iDocumentAttribute> attr = attrIter->Next();
        const char* attrName = attr->GetName();
        if (mode==1  ||  !target->GetAttribute(attrName))
            target->SetAttribute(attrName, attr->GetValue());
    }
}
Ejemplo n.º 2
0
pawsFrameDrawable::pawsFrameDrawable(csRef<iDocumentNode> node)
    : scfImplementationType (this)
{
    defaultTransparentColourBlue  = -1;
    defaultTransparentColourGreen = -1;
    defaultTransparentColourRed   = -1;

    defaultAlphaValue = 0;

    // Read off the image and file vars
    imageFileLocation = node->GetAttributeValue("file");
    resourceName = node->GetAttributeValue("resource");

    csString typeStr(node->GetAttributeValue("type"));
    type = FDT_FULL;
    if (typeStr == "horizontal")
        type = FDT_HORIZONTAL;
    else if (typeStr == "vertical")
        type = FDT_VERTICAL;

    csRef<iDocumentNodeIterator> iter = node->GetNodes();
    while ( iter->HasNext() )
    {
        csRef<iDocumentNode> childNode = iter->Next();

        // Read the default alpha value.
        if (strcmp(childNode->GetValue(), "alpha") == 0)
            defaultAlphaValue = childNode->GetAttributeValueAsInt("level");

        // Read the default transparent colour.
        else if (strcmp(childNode->GetValue(), "trans") == 0)
        {
            defaultTransparentColourRed   = childNode->GetAttributeValueAsInt("r");
            defaultTransparentColourGreen = childNode->GetAttributeValueAsInt("g");
            defaultTransparentColourBlue  = childNode->GetAttributeValueAsInt("b");
        }

        else if (strcmp(childNode->GetValue(), "top_left") == 0)
            LoadPiece(childNode, FDP_TOP_LEFT);
        else if (strcmp(childNode->GetValue(), "top") == 0)
            LoadPiece(childNode, FDP_TOP);
        else if (strcmp(childNode->GetValue(), "top_right") == 0)
            LoadPiece(childNode, FDP_TOP_RIGHT);
        else if (strcmp(childNode->GetValue(), "left") == 0)
            LoadPiece(childNode, FDP_LEFT);
        else if (strcmp(childNode->GetValue(), "middle") == 0)
            LoadPiece(childNode, FDP_MIDDLE);
        else if (strcmp(childNode->GetValue(), "right") == 0)
            LoadPiece(childNode, FDP_RIGHT);
        else if (strcmp(childNode->GetValue(), "bottom_left") == 0)
            LoadPiece(childNode, FDP_BOTTOM_LEFT);
        else if (strcmp(childNode->GetValue(), "bottom") == 0)
            LoadPiece(childNode, FDP_BOTTOM);
        else if (strcmp(childNode->GetValue(), "bottom_right") == 0)
            LoadPiece(childNode, FDP_BOTTOM_RIGHT);
    }

}
Ejemplo n.º 3
0
pawsImageDrawable::pawsImageDrawable(csRef<iDocumentNode> node)
                 : scfImplementationType (this)
{
    debugImageErrors = true;
    defaultTransparentColourBlue  = -1;
    defaultTransparentColourGreen = -1;
    defaultTransparentColourRed   = -1;

    defaultAlphaValue = 0;

    // Read off the image and file vars
    imageFileLocation = node->GetAttributeValue( "file" );
    resourceName = node->GetAttributeValue( "resource" );

    tiled = node->GetAttributeValueAsBool("tiled");

    csRef<iDocumentNodeIterator> iter = node->GetNodes();
    while ( iter->HasNext() )
    {
        csRef<iDocumentNode> childNode = iter->Next();       

        // Read the texture rectangle for this image.
        if ( strcmp( childNode->GetValue(), "texturerect" ) == 0 )
        {
            textureRectangle.xmin = childNode->GetAttributeValueAsInt("x");
            textureRectangle.ymin = childNode->GetAttributeValueAsInt("y");

            int width = childNode->GetAttributeValueAsInt("width");
            int height = childNode->GetAttributeValueAsInt("height");

            textureRectangle.SetSize(width, height);
        }

        // Read the default alpha value.
        if ( strcmp( childNode->GetValue(), "alpha" ) == 0 )
        {
            defaultAlphaValue = childNode->GetAttributeValueAsInt("level");            
        }

        // Read the default transparent colour.
        if ( strcmp( childNode->GetValue(), "trans" ) == 0 )
        {
            defaultTransparentColourRed   = childNode->GetAttributeValueAsInt("r");            
            defaultTransparentColourGreen = childNode->GetAttributeValueAsInt("g");            
            defaultTransparentColourBlue  = childNode->GetAttributeValueAsInt("b");                                    
        }
    }

    PreparePixmap();
}
Ejemplo n.º 4
0
csString GetNodeXML(csRef<iDocumentNode> node, bool childrenOnly)
{
    psString xml;
    csRef<iDocumentNodeIterator> nodes;
    csRef<iDocumentAttributeIterator> attrs;
    
    if (!childrenOnly)
        xml.Format("<%s", node->GetValue());
    
    attrs = node->GetAttributes();
    while (attrs->HasNext())
    {
        csRef<iDocumentAttribute> attr = attrs->Next();
    csString escpxml = EscpXML(attr->GetValue());
        xml.AppendFmt(" %s=\"%s\"", attr->GetName(), escpxml.GetData() );
    }
    if (!childrenOnly)
        xml += ">";
    

    nodes = node->GetNodes();
    if (nodes->HasNext())
    {
        while (nodes->HasNext())
        {
            csRef<iDocumentNode> child = nodes->Next();
            if (child->GetType() == CS_NODE_TEXT)
            {
                // add the node-content to the string..but escape special XML chars in it
                xml += EscpXML(child->GetContentsValue());
            }
            else
            {
                xml += GetNodeXML(child);
            }
        }
    }
    if (!childrenOnly)
    {
        // add the node-content to the string..but escape special XML chars in it
        xml += EscpXML(node->GetContentsValue());
        xml.AppendFmt("</%s>", node->GetValue());
    }
    return xml;
}
Ejemplo n.º 5
0
void OptimiseData::ParseMeshObj(csArray<csString>& libsNeeded, csArray<csString>& materialsNeeded,
                                csString& mapInPath, csRef<iDocumentNode> meshobj)
{
  csRef<iDocumentNodeIterator> meshobjs = meshobj->GetNodes("meshobj");
  while(meshobjs->HasNext())
  {
    ParseMeshObj(libsNeeded, materialsNeeded, mapInPath, meshobjs->Next());
  }

  if(meshobj->GetNode("params"))
  {
    meshobj = meshobj->GetNode("params");
    if(meshobj->GetNode("factory"))
    {
      bool found = false;
      for(size_t i=0; i<meshFactsOut.GetSize(); i++)
      {
        if(csString(meshFactsOut[i]->GetRoot()->GetNode("library")->GetNode("meshfact")->GetAttributeValue("name")).Compare(meshobj->GetNode("factory")->GetContentsValue()))
        {
          libsNeeded.PushSmart(meshobj->GetNode("factory")->GetContentsValue());
          found = true;
        }
      }

      if(!found)
      {
        // Print error and mark data as incorrect.
        csFPrintf(stderr, "ERROR: Mesh object %s uses mesh factory %s but there is no factory data!\n",
          meshobj->GetAttributeValue("name"), meshobj->GetNode("factory")->GetContentsValue());
      }
    }
    if(meshobj->GetNode("material"))
    {
      bool found = false;
      for(size_t i=0; i<materials.GetSize(); i++)
      {
        if(csString(materials[i]->GetAttributeValue("name")).Compare(meshobj->GetNode("material")->GetContentsValue()))
        {
          materialsNeeded.PushSmart(meshobj->GetNode("material")->GetContentsValue());
          found = true;
        }
      }

      if(!found)
      {
        // Print error and mark data as incorrect.
        csFPrintf(stderr, "ERROR: Mesh object %s uses material %s but there is no such material declaration!\n",
          meshobj->GetAttributeValue("name"), meshobj->GetNode("material")->GetContentsValue());
      }
    }
  }
  else if(meshobj->GetNode("paramsfile"))
  {
    csString paramsPath = mapInPath + "/" + meshobj->GetNode("paramsfile")->GetContentsValue();
    csRef<iFile> file = vfs->Open(paramsPath, VFS_FILE_READ);
    csRef<iDocument> paramsDoc = docSys->CreateDocument();
    paramsDoc->Parse(file);
    meshobj = paramsDoc->GetRoot()->GetNode("params");
    if(meshobj->GetNode("factory"))
    {
      bool found = false;
      for(size_t i=0; i<meshFactsOut.GetSize(); i++)
      {
        if(csString(meshFactsOut[i]->GetRoot()->GetNode("library")->GetNode("meshfact")->GetAttributeValue("name")).Compare(meshobj->GetNode("factory")->GetContentsValue()))
        {
          libsNeeded.PushSmart(meshobj->GetNode("factory")->GetContentsValue());
          found = true;
        }
      }

      if(!found)
      {
        // Print error and mark data as incorrect.
        csFPrintf(stderr, "ERROR: Mesh object %s uses mesh factory %s but there is no factory data!\n",
          meshobj->GetParent()->GetAttributeValue("name"), meshobj->GetNode("factory")->GetContentsValue());
      }
    }
    if(meshobj->GetNode("material"))
    {
      bool found = false;
      for(size_t i=0; i<materials.GetSize(); i++)
      {
        if(csString(materials[i]->GetAttributeValue("name")).Compare(meshobj->GetNode("material")->GetContentsValue()))
        {
          materialsNeeded.PushSmart(meshobj->GetNode("material")->GetContentsValue());
          found = true;
        }
      }

      if(!found)
      {
        // Print error and mark data as incorrect.
        csFPrintf(stderr, "ERROR: Mesh object %s uses material %s but there is no such material declaration!\n",
          meshobj->GetParent()->GetAttributeValue("name"), meshobj->GetNode("material")->GetContentsValue());
      }
    }
  }
}
Ejemplo n.º 6
0
void OptimiseData::ParseMeshFact(csRef<iDocumentNode>& meshFact, csRef<iDocumentNode>& tempDocRoot,
                                 csRefArray<iDocumentNode>& tempMats)
{
  csRef<iDocumentNode> params = meshFact->GetNode("params");
  if(params.IsValid())
  {
    bool first = true;
    csRef<iDocumentNodeIterator> submeshes = params->GetNodes("submesh");
    if(!submeshes->HasNext())
    {
      submeshes = params->GetNodes("curve");
    }

    while((first && params->GetNode("material")) || submeshes->HasNext())
    {
      csString materialName;
      if(first && params->GetNode("material"))
      {
        materialName = params->GetNode("material")->GetContentsValue();
        first = false;
      }
      else if(submeshes->HasNext())
      {
        csRef<iDocumentNode> submesh = submeshes->Next();
        if(submesh->GetNode("material"))
        {
          materialName = submesh->GetNode("material")->GetContentsValue();
        }
        else
        {
          continue;
        }
      }

      bool hasMaterialDecl = false;

      csRef<iDocumentNode> material;
      for(size_t j=0; j<materials.GetSize(); j++)
      {
        material = materials[j];
        if(materialName.Compare(material->GetAttributeValue("name")))
        {
          hasMaterialDecl = true;
          break;
        }
      }

      if(!hasMaterialDecl)
      {
        // Print error and mark data as incorrect.
        csFPrintf(stderr, "ERROR: Meshfact %s uses material %s but there is no material declaration!\n",
          meshFact->GetAttributeValue("name"), materialName.GetData());
      }

      tempMats.PushSmart(material);
    }
  }

  csRef<iDocumentNodeIterator> undermeshes = meshFact->GetNodes("meshfact");
  while(undermeshes->HasNext())
  {
    csRef<iDocumentNode> next = undermeshes->Next();
    ParseMeshFact(next, tempDocRoot, tempMats);
  }
}
Ejemplo n.º 7
0
bool psEntity::DefineState(csRef<iDocumentNode> stateNode)
{

    int stateID;

    EntityState* entityState;
    csRef<iDocumentNodeIterator> resourceItr;

    // checking if the state ID is legal
    stateID = stateNode->GetAttributeValueAsInt("ID", -1);
    Debug4(LOG_SOUND, 0, "psEntity::DefineState %s state %d meshid %u",entityName.GetData(),stateID,id);
    if(stateID < 0)
    {
        return false;
    }

    // initializing the EntityState
    entityState = states.Get(stateID, 0);

    if(entityState != 0) // already defined
    {
        return false;
    }

    entityState = new EntityState();

    // initializing resources
    resourceItr = stateNode->GetNodes("RESOURCE");
    while(resourceItr->HasNext())
    {
        const char* resourceName = resourceItr->Next()->GetAttributeValue("NAME", 0);
        if(resourceName == 0)
        {
            continue;
        }
        entityState->resources.PushSmart(resourceName);
    }

    // checking if there is at least one resource
    if(entityState->resources.IsEmpty())
    {
        delete entityState;
        return false;
    }

    // setting all the other parameters
    entityState->probability = stateNode->GetAttributeValueAsFloat("PROBABILITY", 1.0);
    entityState->volume = stateNode->GetAttributeValueAsFloat("VOLUME", VOLUME_NORM);
    entityState->delay = stateNode->GetAttributeValueAsInt("DELAY", 0);
    entityState->timeOfDayStart = stateNode->GetAttributeValueAsInt("TIME_START", 0);
    entityState->timeOfDayEnd = stateNode->GetAttributeValueAsInt("TIME_END", 24);
    entityState->fallbackState = stateNode->GetAttributeValueAsInt("FALLBACK_STATE", UNDEFINED_ENTITY_STATE);
    entityState->fallbackProbability = stateNode->GetAttributeValueAsFloat("FALLBACK_PROBABILITY", 0.0);
    entityState->references = 1;

    // adjusting the probabilities on the update time
    if(entityState->probability < 1.0)
    {
        entityState->probability *= SoundManager::updateTime / 1000.0;
    }
    if(entityState->fallbackProbability < 1.0)
    {
        entityState->fallbackProbability *= SoundManager::updateTime / 1000.0;
    }

    // in XML delay is given in seconds, converting delay into milliseconds
    entityState->delay = entityState->delay * 1000;

    states.Put(stateID, entityState);

    return true;
}