Exemplo n.º 1
0
bool celHNavStructBuilder::ParseGraph (iDocumentNode* node, iCelGraph* graph, csHash<csRef<iSector>, const char*> sectors)
{
  csRef<iDocumentNode> nodesNode = node->GetNode("nodes");
  csRef<iDocumentNodeIterator> it = nodesNode->GetNodes("node");
  size_t nodeCount = it->GetEndPosition();
  csArray<csRef<iCelNode> > celNodes(nodeCount);
  celNodes.SetSize(nodeCount);
  while (it->HasNext())
  {
    csRef<iDocumentNode> graphNode = it->Next();
    size_t id = graphNode->GetAttributeValueAsInt("id");

    // Get sector
    const char* sectorName = graphNode->GetAttributeValue("sector");
    csRef<iSector> sector = sectors.Get(sectorName, 0);
    if(!sector.IsValid())
    {
        csString msg;
        msg.Format("invalid sector %s in navmesh graph node\n", sectorName);
        CS_ASSERT_MSG(msg.GetData(),false);
    }

    // Get position
    csVector3 position;
    float x = graphNode->GetAttributeValueAsFloat("x");
    float y = graphNode->GetAttributeValueAsFloat("y");
    float z = graphNode->GetAttributeValueAsFloat("z");
    position.Set(x, y, z);
    
    // Crete node
    csRef<iCelNode> node = graph->CreateEmptyNode(id);
    celNodes[id] = node;
    csRef<iMapNode> mapNode;
    mapNode.AttachNew(new csMapNode("n"));
    mapNode->SetPosition(position);
    mapNode->SetSector(sector);
    node->SetMapNode(mapNode);
  }

  csRef<iDocumentNode> edgesNode = node->GetNode("edges");
  it = edgesNode->GetNodes("edge");
  while (it->HasNext())
  {
    csRef<iDocumentNode> graphEdge = it->Next();
    int from = graphEdge->GetAttributeValueAsInt("from");
    int to = graphEdge->GetAttributeValueAsInt("to");
    float weight = graphEdge->GetAttributeValueAsFloat("weight");
    celNodes[from]->AddSuccessor(celNodes[to], true, weight);
  }

  return true;
}
Exemplo n.º 2
0
bool csDriverDBReader::ParseConfigs (iDocumentNode* node)
{
  csRef<iDocumentNodeIterator> it (node->GetNodes ());
  while (it->HasNext())
  {
    csRef<iDocumentNode> child = it->Next();
    if (child->GetType() != CS_NODE_ELEMENT) continue;
    csStringID token = tokens.Request (child->GetValue ());

    switch (token)
    {
      case XMLTOKEN_CONFIG:
	{
	  const char* name = child->GetAttributeValue ("name");
	  if (!name)
	  {
	    db->Report (
	      CS_REPORTER_SEVERITY_WARNING,
	      child,
	      "<config> has no name");
	    return false;
	  }
	  csRef<csConfigDocument> cfg (configs.Get (name, 
	    (csConfigDocument*)0));
	  if (!cfg.IsValid ())
	  {
	    cfg.AttachNew (new csConfigDocument ());
	    configs.Put (name, cfg);
	  }
	  cfg->LoadNode (child, true, true);
	}
	break;
      default:
	db->ReportBadToken (child);
	return false;
    }
  }
  return true;
}
Exemplo n.º 3
0
bool csDriverDBReader::Apply (iDocumentNode* node)
{
  csRef<iDocumentNodeIterator> it (node->GetNodes ());
  while (it->HasNext())
  {
    csRef<iDocumentNode> child = it->Next();
    if (child->GetType() != CS_NODE_ELEMENT) continue;
    csStringID token = tokens.Request (child->GetValue ());

    switch (token)
    {
      case XMLTOKEN_USECFG:
	{
	  const char* cfgname = child->GetContentsValue ();
	  csRef<csConfigDocument> cfg (configs.Get (cfgname, 
	    (csConfigDocument*)0));
	  if (!cfg.IsValid ())
	  {
	    db->Report (
	      CS_REPORTER_SEVERITY_WARNING,
	      child,
	      "unknown config %s", cfgname);
	  }
	  else
	  {
	    cfgmgr->AddDomain (cfg, usedCfgPrio);
	    db->addedConfigs.Push (cfg);
	  }
	}
	break;
      default:
	db->ReportBadToken (child);
	return false;
    }
  }
  return true;
}