Ejemplo n.º 1
0
  //
  // SaveObjectFile
  //
  // Save all objects, false if unable to create file
  //
  Bool SaveObjectFile(const char *name)
  {
    PTree pTree;
    FilePath path;

    // Get the global scope of the parse tree
    FScope *gScope = pTree.GetGlobalScope();

    // Save every game object
    for (NList<GameObj>::Iterator i(&GameObjCtrl::listAll); *i; i++)
    {
      SaveCreateObject(gScope, *i);
    }

    // Work out save path
    Dir::PathMake(path, Missions::GetWritePath(), name);
  
    // Write the file
    if (!CoreGame::WriteTree(pTree, path.str))
    {
      LOG_WARN(("Unable to write to file [%s]", path.str));
      return (FALSE);
    }

    // Success
    return (TRUE);
  }
Ejemplo n.º 2
0
int
main( int argc, char *argv[] )
{
    istream *br;
    ifstream infile;
    
    if( argc == 1 )
        br = &cin;
    else if( argc == 2 ) {
        infile.open(argv[1]);
        if( infile.is_open() )
            br = &infile;
        else {
            usage(argv[0], "Cannot open " + string(argv[1]));
            return 1;
        }
    }
    else {
        usage(argv[0], "More than one file name was given");
        return 1;
    }
    
    PTree *program;
    program = Program(br);
    //evaluate the program
    program->eval();
    
    
    
}
Ejemplo n.º 3
0
int
main( int argc, char *argv[] )
{
    istream *br;
    ifstream infile;
    
    if( argc == 1 )
        br = &cin;
    else if( argc == 2 ) {
        infile.open(argv[1]);
        if( infile.is_open() )
            br = &infile;
        else {
            usage(argv[0], "Cannot open " + string(argv[1]));
            return 1;
        }
    }
    else {
        usage(argv[0], "More than one file name was given");
        return 1;
    }

    PTree *program;

    program = Program(br);

    if( !program || errcnt )
    	return 0;
    
    cout << "Node Count Is: " << program->nodeCount() << endl;
    program->findEmptyStrings();
    program->findInvalidOps();
    
    return 0;
}
Ejemplo n.º 4
0
Game::HeroInfo::HeroInfo(const PTree& root) :
    name(root.get<std::string>("name")),
    user_id(root.get("userId", "")),
    elo(root.get("elo", -1)),
    crashed(root.get("crashed",false))
{
}
Ejemplo n.º 5
0
Game::Game(const PTree& root) :
    background_tiles(get_background_tiles(root.get_child("game.board"))),
    hashed_background_tiles(make_hashed_pair(background_tiles)),
    turn_max(root.get<int>("game.maxTurns")),
    turn(root.get<int>("game.turn")),
    state(root, hashed_background_tiles)
{
    assert( state == state );
    assert( hash_value(state) == hash_value(state) );

    int kk = 0;
    const PTree& child_heroes = root.get_child("game.heroes");
    for (PTree::const_iterator ti=child_heroes.begin(), tie=child_heroes.end(); ti!=tie; ti++)
    {
#if !defined(NDEBUG)
        const int id = ti->second.get<int>("id");
        assert( kk+1 == id );
#endif

        const_cast<HeroInfo&>(hero_infos[kk]) = HeroInfo(ti->second);

        assert( kk < 4 );
        kk++;
    }

}
Ejemplo n.º 6
0
vector<SurfaceSample> SurfaceSample::loadFromXML(const std::string& filename) {
    vector<SurfaceSample> samples;

    try {
        PTree tree;
        read_xml(filename, tree);

        PTree root = tree.get_child("SurfaceSamples");

        for (CI p = root.begin(); p != root.end(); ++p) {
            if (p->first == "Sample") {
                Q posq = XMLHelpers::readQ(p->second.get_child("Pos"));
                Q rpyq = XMLHelpers::readQ(p->second.get_child("RPY"));
                double graspW = XMLHelpers::readDouble(p->second.get_child("GraspW"));
                //cout << "pos=" << posq << " rot=" << rpyq << " graspW=" << graspW << endl;

                Vector3D<> pos(posq[0], posq[1], posq[2]);
                RPY<> rpy(rpyq[0], rpyq[1], rpyq[2]);
                samples.push_back(SurfaceSample(Transform3D<>(pos, rpy.toRotation3D()), graspW));
            }
        }
    } catch (const ptree_error& e) {
        RW_THROW(e.what());
    }

    return samples;
}
Ejemplo n.º 7
0
	void read(PTree & node)
	{
		std::string line, name;
		while (in.good())
		{
			std::getline(in, line, '\n');
			if (line.empty())
			{
				continue;
			}

			size_t begin = line.find_first_not_of(" \t[");
			size_t end = line.find_first_of(";#]\r", begin);
			if (begin >= end)
			{
				continue;
			}

			size_t next = line.find("=", begin);
			if (next >= end)
			{
				// New node.
				next = line.find_last_not_of(" \t\r]", end);
				name = line.substr(begin, next);
				read(root.set(name, PTree()));
				continue;
			}

			size_t next2 = line.find_first_not_of(" \t\r", next+1);
			next = line.find_last_not_of(" \t", next-1);
			if (next2 >= end)
				continue;

			name = line.substr(begin, next+1);
			if (!fopen || line.at(next2) != '&')
			{
				// New property.
				std::string value = line.substr(next2, end-next2);
				node.set(name, value);
				continue;
			}

			// Value is a reference.
			std::string value = line.substr(next2+1, end-next2-1);
			const PTree * ref_ptr;
			if (root.get(value, ref_ptr) || cache.get(value, ref_ptr))
			{
				node.set(name, *ref_ptr);
				continue;
			}

			// Load external reference.
			PTree ref;
			read_ini(value, *fopen, ref);
			cache.set(value, ref);
			node.set(name, ref);
		}
	}
Ejemplo n.º 8
0
static void read_xml(std::istream & in, PTree & node, Include * include, std::string key)
{
	std::string line, escape("/"+node.value());
	while (in.good())
	{
		std::getline(in, line, '\n');
		if (line.empty())
		{
			continue;
		}

		size_t begin = line.find_first_not_of(" \t\n<");
		size_t end = line.length();
		if (begin >= end || line[begin] == '!')
		{
			continue;
		}

		line = line.substr(begin, end);

		if (line.find(escape) == 0)
		{
			break;
		}

		if (key.length() == 0)
		{
			end = line.find(" ");
			key = line.substr(0, end);
			continue;
		}

		size_t next = line.find("</"+key);
		if (next < end)
		{
			// New property.
			std::string value = line.substr(0, next);

			// Include?
			if (include && key == "include")
			{
				(*include)(node, value);
			}
			else
			{
				node.set(key, value);
			}
		}
		else
		{
			// New node.
			end = line.find(" ");
			std::string child_key = line.substr(0, end);
			read_xml(in, node.set(key, PTree()), include, child_key);
		}
		key.clear();
	}
}
Ejemplo n.º 9
0
  //
  // LoadObjectFile
  //
  // Load a object definition file into current state, false if not found
  //
  Bool LoadObjectFile(const char *name)
  {
    ASSERT(name);

    PTree pTree;
    Bool safe = Missions::GetSafeLoad();

    // Parse the file
    GameGod::Loader::SubSystem("#game.loader.createobjects", 1);

    if (pTree.AddFile(name))
    {
      // Get the global scope
      FScope *gScope = pTree.GetGlobalScope();
      FScope *sScope;

      // Process each function
      GameGod::Loader::SubSystem("#game.loader.createobjects", gScope->GetBodyCount());

      while ((sScope = gScope->NextFunction()) != NULL)
      {
        switch (sScope->NameCrc())
        {
          case 0xCAE286FA: // "CreateObject"
            LoadCreateObject(sScope, safe);
            GameGod::Loader::Advance();
            break;
        }
      }

      if (GameGod::CheckObjects())
      {
        FSCOPE_CHECK(gScope)
      }

      // Call each existing game object
      GameGod::Loader::SubSystem("#game.loader.configureobjects", GameObjCtrl::listAll.GetCount());

      for (NList<GameObj>::Iterator i(&GameObjCtrl::listAll); *i; i++)
      {
        // Are we in safe-mode and this is a map object
        if (safe && Promote::Object<MapObjType, MapObj>(*i))
        {
        }
        else
        {
          // Call virtual post-load function
          (*i)->PostLoad();
        }

        GameGod::Loader::Advance();
      }

      return (TRUE);
    }
Ejemplo n.º 10
0
  //
  // Export
  //
  // Export this footprint to the given file name
  //
  Bool Type::Export(const char *fileName)
  {
    PTree tree;
    FScope *root, *cellInfo;
  
    // Add the top level scope
    root = tree.GetGlobalScope()->AddFunction("ConfigureFootPrint");

    // Get the layer used for zipping
    Layer &layer = GetLayer(LAYER_LOWER);

    // Save out the grid
    for (S32 z = 0; z <= size.z; z++)
    {
      for (S32 x = 0; x <= size.x; x++)
      {
        // Write out cell info
        cellInfo = root->AddFunction("SetupCell");
        cellInfo->AddArgInteger(x);
        cellInfo->AddArgInteger(z);

        // Is this cell on the footprint
        if (x < size.x && z < size.z)
        {
          Cell &cell = GetCell(x, z);
          StdSave::TypeU32(cellInfo, "Hide", cell.GetFlag(HIDE));
          StdSave::TypeU32(cellInfo, "SetBase", cell.GetFlag(SETBASE));
          StdSave::TypeU32(cellInfo, "Second", cell.GetFlag(SECOND));
          StdSave::TypeU32(cellInfo, "Dirs", cell.dirs);
          StdSave::TypeU32(cellInfo, "ClaimLo", cell.GetFlag(CLAIMLO));
          StdSave::TypeU32(cellInfo, "ClaimHi", cell.GetFlag(CLAIMHI));
          StdSave::TypeU32(cellInfo, "BlockLOS", cell.GetFlag(BLOCKLOS));

          if (cell.GetFlag(SURFACE))
          {
            MoveTable::KeyInfo *info = MoveTable::FindSurfaceInfo(cell.surface);

            if (info)
            {
              StdSave::TypeString(cellInfo, "Surface", info->ident.str);
            }
          }
        }

        Layer::Cell &cell = layer.GetCell(x, z);
        StdSave::TypeU32(cellInfo, "Zip", cell.GetFlag(Layer::ZIP));
      }
    }
  
    // Save out to disk
    return (tree.WriteTreeText(fileName));
  }
Ejemplo n.º 11
0
static void read_inf(std::istream & in, PTree & node, Include * include, bool child)
{
	std::string line, name;
	while (in.good())
	{
		std::getline(in, line, '\n');
		if (line.empty())
		{
			continue;
		}

		size_t begin = line.find_first_not_of(" \t");
		size_t end = line.find_first_of(";#");
		if (begin >= end)
		{
			continue;
		}

		line = line.substr(begin, end);
		if (line[0] == '{' && name.length())
		{
			// New node.
			read_inf(in, node.set(name, PTree()), include, true);
			continue;
		}

		if (line[0] == '}' && child)
		{
			break;
		}

		size_t next = line.find(" ");
		end = line.length();
		name = line.substr(0, next);
		if (next < end)
		{
			// New property.
			std::string value = line.substr(next+1, end);

			// Include?
			if (include && name == "include")
			{
				(*include)(node, value);
			}
			else
			{
				node.set(name, value);
			}
			name.clear();
		}
	}
}
Ejemplo n.º 12
0
  //
  // LoadConfig
  //
  // Load the configured difficulty settings
  //
  static void LoadConfig()
  {
    PTree pTree;
    GameIdent defaultName;

    // Clear any current settings
    ClearSettings();

    // Open the configuration file
    if (pTree.AddFile(configName))
    {
      FScope *gScope = pTree.GetGlobalScope();
      FScope *sScope;

      // Parse each function
      while ((sScope = gScope->NextFunction()) != NULL)
      {
        switch (sScope->NameCrc())
        {
          case 0x12AFF0D8: // "CreateSetting"
            ProcessCreateSetting(sScope);
            break;

          case 0x733C1EB5: // "DefaultSetting"
            defaultName = StdLoad::TypeString(sScope);
            break;
        }
      }

      // Ensure at least one setting is configured
      if (settings.GetCount())
      {
        // Setup the default setting
        if ((defaultSetting = FindSetting(defaultName)) == NULL)
        {
          defaultSetting = settings.GetHead();
        }

        // Set the current from the default
        currentSetting = defaultSetting;
      }
      else
      {
        ERR_CONFIG(("At least one difficulty setting must be supplied in [%s]", configName));
      }
    }
    else
    {
      ERR_CONFIG(("Unable to load difficulty settings configuration [%s]", configName));
    }
  }
Ejemplo n.º 13
0
static bool LoadCoilover(
	const PTree & cfg,
	CarSuspensionInfo & info,
	std::ostream & error_output)
{
	if (!cfg.get("spring-constant", info.spring_constant, error_output)) return false;
	if (!cfg.get("bounce", info.bounce, error_output)) return false;
	if (!cfg.get("rebound", info.rebound, error_output)) return false;
	if (!cfg.get("travel", info.travel, error_output)) return false;
	if (!cfg.get("anti-roll", info.anti_roll, error_output)) return false;
	LoadPoints(cfg, "damper-factor-", info.damper_factors);
	LoadPoints(cfg, "spring-factor-", info.spring_factors);
	return true;
}
Ejemplo n.º 14
0
bool LoadDrawable::operator()(
	const PTree & cfg,
	SCENENODE & topnode,
	keyed_container<SCENENODE>::handle * nodehandle,
	keyed_container<DRAWABLE>::handle * drawhandle)
{
	std::vector<std::string> texname;
	if (!cfg.get("texture", texname)) return true;

	std::string meshname;
	if (!cfg.get("mesh", meshname, error)) return false;

	return operator()(meshname, texname, cfg, topnode, nodehandle, drawhandle);
}
Ejemplo n.º 15
0
bool CAR::LoadPhysics(
	const PTree & cfg,
	const std::string & carpath,
	const MATHVECTOR <float, 3> & initial_position,
	const QUATERNION <float> & initial_orientation,
	const bool defaultabs,
	const bool defaulttcs,
	const bool damage,
	ContentManager & content,
	DynamicsWorld & world,
	std::ostream & error_output)
{
	std::string carmodel;
	std::tr1::shared_ptr<MODEL> modelptr;
	if (!cfg.get("body.mesh", carmodel, error_output)) return false;
	if (!content.load(carpath, carmodel, modelptr)) return false;

	btVector3 size = ToBulletVector(modelptr->GetSize());
	btVector3 center = ToBulletVector(modelptr->GetCenter());
	btVector3 position = ToBulletVector(initial_position);
	btQuaternion rotation = ToBulletQuaternion(initial_orientation);

	if (!dynamics.Load(cfg, size, center, position, rotation, damage, world, error_output)) return false;
	dynamics.SetABS(defaultabs);
	dynamics.SetTCS(defaulttcs);

	mz_nominalmax = (GetTireMaxMz(FRONT_LEFT) + GetTireMaxMz(FRONT_RIGHT)) * 0.5;

	return true;
}
Ejemplo n.º 16
0
bool CarGraphics::LoadCameras(
	const PTree & cfg,
	const float cambounce,
	std::ostream & error_output)
{
	const PTree * cfg_cams;
	if (!cfg.get("camera", cfg_cams))
	{
		return false;
	}

	if (!cfg_cams->size())
	{
		error_output << "No cameras defined." << std::endl;
		return false;
	}

	cameras.reserve(cfg_cams->size());
	for (PTree::const_iterator i = cfg_cams->begin(); i != cfg_cams->end(); ++i)
	{
		Camera * cam = LoadCamera(i->second, cambounce, error_output);
		if (!cam)
		{
			ClearCameras();
			return false;
		}
		cameras.push_back(cam);
	}

	return true;
}
Ejemplo n.º 17
0
static void read_xml(std::istream & in, PTree & p, std::string key)
{
	std::string line, escape("/"+p.value());
	while (in.good())
	{
		std::getline(in, line, '\n');
		if (line.empty())
		{
			continue;
		}

		size_t begin = line.find_first_not_of(" \t\n<");
		size_t end = line.length();
		if (begin >= end || line[begin] == '!')
		{
			continue;
		}

		line = line.substr(begin, end);

		if (line.find(escape) == 0)
		{
			break;
		}

		if (key.length() == 0)
		{
			end = line.find(" ");
			key = line.substr(0, end);
			continue;
		}

		size_t next = line.find("</"+key);
		if (next < end)
		{
			std::string value = line.substr(0, next);
			p.set(key, value);
		}
		else
		{
			end = line.find(" ");
			std::string child_key = line.substr(0, end);
			read_xml(in, p.set(key, PTree()), child_key);
		}
		key.clear();
	}
}
Ejemplo n.º 18
0
Series Series::fromPTree(PTree& pt)
{
  Series s;

  s.id = pt.get<String>("id");
  s.key = pt.get<String>("key");

  BOOST_FOREACH(PTree::value_type &v,
      pt.get_child("tags"))
    s.tags.push_back(v.second.data());

  BOOST_FOREACH(PTree::value_type &v,
      pt.get_child("attributes"))
    s.attributes[v.first.data()] = v.second.data();

  return s;
}
Ejemplo n.º 19
0
void Decoder::readTable(const char filename[], double prune_threshold,	unsigned int prune_count){
//==================Einlesen der Phrasentabelle============================
	PTree< pair <unsigned int, double> > pruningTree; //speichert für jede Übersetzung die Anzahl der eingelesenen Übersetzungen und die beste Übersetzung
	pair <unsigned int, double> pruningStart; //die Startkombi für den PruningTree
	pruningStart.first=0;
	pruningStart.second=(1./0.);

	igzstream in(filename);
	std::string line,token;


	while(getline(in,line)){
		std::stringstream ist(line);

		double relfreq_f, relfreq_e, source_to_target, target_to_source, unigram_sprachmodell;
		unsigned int singlecf, singlece; 
		vector<uint> ephrase, fphrase;

		//Ausgabe: relfreq_f relfreq_e # quellphrase # zielphrase # singlecf singlece # source_to_target target_to_source #  unigram-sprachmodell
		ist >> relfreq_f  >> relfreq_e >>token; // token für "#"

		while(ist>>token && token != "#"){
			fphrase.push_back(flex->getWord_or_add(token).wordId());
		}
		while(ist>>token && token != "#"){
			ephrase.push_back(elex->getWord_or_add(token).wordId());
		}
		ist >> singlecf >> singlece >> token >> source_to_target >> target_to_source >> token >> unigram_sprachmodell;

		Cost kosten=Cost();
		kosten.calc(relfreq_f, relfreq_e, fphrase, ephrase, singlecf, singlece, source_to_target, target_to_source, unigram_sprachmodell);
		double kosten_insgesamt=kosten.cost();

		pair< unsigned int, double>* pruning_infos=&pruningTree.traverse(fphrase,true,pruningStart)->c;

		if (kosten_insgesamt > pruning_infos->second+prune_threshold || pruning_infos->first >prune_count)	continue; //pruning ergibt, wir wollen es nicht in den Ptree mitaufnehmen

		//if (kosten_insgesamt< pruning_infos->second)	pruning_infos->second=kosten_insgesamt;  _jetzt irrelevant, da ich von einer geordneten eingabe ausgehe
		pruning_infos->first++;

		schwarz->traverse(fphrase,true)->c.traverse(ephrase,true,Cost(1./0.))->c = kosten;

	}
	//cerr << " schwarz erstellt" << endl;

}
Ejemplo n.º 20
0
	void operator()(PTree & node, std::string & value)
	{
		std::tr1::shared_ptr<PTree> sptr;
		if (content.load(sptr, path, value))
		{
			node.set(*sptr);
		}
	}
Ejemplo n.º 21
0
static void write_xml(const PTree & p, std::ostream & out, std::string indent)
{
	for (PTree::const_iterator i = p.begin(), e = p.end(); i != e; ++i)
	{
		if (i->second.size() == 0)
		{
			out << indent << "<" << i->first << ">" << i->second.value() << "</" << i->first << ">\n";
			write_xml(i->second, out, indent+"\t");
		}
		else
		{
			out << indent << "<" << i->first << ">\n";
			write_xml(i->second, out, indent+"\t");
			out << indent << "</" << i->first << ">\n";
		}
	}
}
Ejemplo n.º 22
0
bool CarGraphics::LoadLight(
	const PTree & cfg,
	ContentManager & content,
	std::ostream & error_output)
{
	float radius;
	std::string radiusstr;
	Vec3 pos(0), col(0);
	if (!cfg.get("position", pos, error_output)) return false;
	if (!cfg.get("color", col, error_output)) return false;
	if (!cfg.get("radius", radius, error_output)) return false;
	cfg.get("radius", radiusstr);

	lights.push_back(Light());

	SceneNode & bodynoderef = topnode.GetNode(bodynode);
	lights.back().node = bodynoderef.AddNode();

	SceneNode & node = bodynoderef.GetNode(lights.back().node);
	node.GetTransform().SetTranslation(Vec3(pos[0], pos[1], pos[2]));

	std::shared_ptr<Model> mesh;
	if (!content.get(mesh, "", "cube" + radiusstr))
	{
		VertexArray varray;
		varray.SetToUnitCube();
		varray.Scale(radius, radius, radius);
		content.load(mesh, "", "cube" + radiusstr, varray);
	}
	models.insert(mesh);

	keyed_container <Drawable> & dlist = node.GetDrawList().lights_omni;
	lights.back().draw = dlist.insert(Drawable());

	Drawable & draw = dlist.get(lights.back().draw);
	draw.SetColor(col[0], col[1], col[2]);
	draw.SetModel(*mesh);
	draw.SetCull(true);
	draw.SetDrawEnable(false);

	return true;
}
Ejemplo n.º 23
0
bool CAR::LoadLight(
	const PTree & cfg,
	ContentManager & content,
	std::ostream & error_output)
{
	float radius;
	std::string radiusstr;
	MATHVECTOR<float, 3> pos(0), col(0);
	if (!cfg.get("position", pos, error_output)) return false;
	if (!cfg.get("color", col, error_output)) return false;
	if (!cfg.get("radius", radius, error_output)) return false;
	cfg.get("radius", radiusstr);

	lights.push_back(LIGHT());

	SCENENODE & bodynoderef = topnode.GetNode(bodynode);
	lights.back().node = bodynoderef.AddNode();

	SCENENODE & node = bodynoderef.GetNode(lights.back().node);
	node.GetTransform().SetTranslation(MATHVECTOR<float,3>(pos[0], pos[1], pos[2]));

	std::tr1::shared_ptr<MODEL> mesh;
	if (!content.get("", "cube"+radiusstr, mesh))
	{
		VERTEXARRAY varray;
		varray.SetToUnitCube();
		varray.Scale(radius, radius, radius);
		content.load("", "cube"+radiusstr, varray, mesh);
	}
    models.push_back(mesh);

	keyed_container <DRAWABLE> & dlist = GetDrawlist(node, OMNI);
	lights.back().draw = dlist.insert(DRAWABLE());

	DRAWABLE & draw = dlist.get(lights.back().draw);
	draw.SetColor(col[0], col[1], col[2]);
	draw.SetModel(*mesh);
	draw.SetCull(true, true);
	draw.SetDrawEnable(false);

	return true;
}
Ejemplo n.º 24
0
String Series::toJson() const
{
  PTree pt;
  pt.put("id", id);
  pt.put("key", key);
  pt.put("name", name);

  PTree ptags;
  BOOST_FOREACH(const std::string tag, tags) {
    PTree t;
    t.put("", tag);
    ptags.push_back(std::make_pair("", t));
  }
Ejemplo n.º 25
0
static void write_ini(const PTree & p, std::ostream & out, std::string key_name)
{
	for (PTree::const_iterator i = p.begin(), e = p.end(); i != e; ++i)
	{
		if (i->second.size() == 0)
		{
			out << i->first << " = " << i->second.value() << "\n";
		}
	}
	out << "\n";

	for (PTree::const_iterator i = p.begin(), e = p.end(); i != e; ++i)
	{
		if (i->second.size() > 0)
		{
			out << "[" << key_name + i->first << "]\n";
			write_ini(i->second, out, key_name + i->first + ".");
		}
	}
}
Ejemplo n.º 26
0
  //
  // ExecInitialConfig
  //
  // Executes the config file for this application
  //
  void ExecInitialConfig()
  {
    PTree pTree;

    // Attempt to open the file
    if (pTree.AddFile(APPLICATION_CONFIGFILE))
    {
      // Find our startup scope
      FScope *fScope = pTree.GetGlobalScope()->GetFunction("StartupConfig", FALSE);

      // Config is not required
      if (fScope)
      {
        Main::ProcessCmdScope(fScope);
      }
    }
    else
    {
      ERR_FATAL(("Unable to execute the required file '%s'", APPLICATION_CONFIGFILE));    
    }
  }
Ejemplo n.º 27
0
bool LoadDrawable::operator()(
	const std::string & meshname,
	const std::vector<std::string> & texname,
	const PTree & cfg,
	SCENENODE & topnode,
	keyed_container<SCENENODE>::handle * nodeptr,
	keyed_container<DRAWABLE>::handle * drawptr)
{
	DRAWABLE drawable;

	// set textures
	TEXTUREINFO texinfo;
	texinfo.mipmap = true;
	texinfo.anisotropy = anisotropy;
	std::tr1::shared_ptr<TEXTURE> tex;
	if (texname.size() == 0)
	{
		error << "No texture defined" << std::endl;
		return false;
	}
	if (texname.size() > 0)
	{
		if (!content.load(path, texname[0], texinfo, tex)) return false;
		drawable.SetDiffuseMap(tex);
	}
	if (texname.size() > 1)
	{
		if (!content.load(path, texname[1], texinfo, tex)) return false;
		drawable.SetMiscMap1(tex);
	}
	if (texname.size() > 2)
	{
		if (!content.load(path, texname[2], texinfo, tex)) return false;
		drawable.SetMiscMap2(tex);
	}

	// set mesh
	std::tr1::shared_ptr<MODEL> mesh;
	if (!content.load(path, meshname, mesh)) return false;

	std::string scalestr;
	if (cfg.get("scale", scalestr) &&
		!content.get(path, meshname + scalestr, mesh))
	{
		MATHVECTOR<float, 3> scale;
		std::stringstream s(scalestr);
		s >> scale;

		VERTEXARRAY meshva = mesh->GetVertexArray();
		meshva.Scale(scale[0], scale[1], scale[2]);
		content.load(path, meshname + scalestr, meshva, mesh);
	}
Ejemplo n.º 28
0
// 1-9 points
static void LoadPoints(const PTree & cfg, const std::string & name, LinearInterp<btScalar> & points)
{
	int i = 1;
	std::stringstream s;
	s << std::setw(1) << i;
	std::vector<btScalar> point(2);
	while (cfg.get(name+s.str(), point) && i < 10)
	{
		s.clear();
		s << std::setw(1) << ++i;
		points.AddPoint(point[0], point[1]);
	}
}
Ejemplo n.º 29
0
  //
  // LoadConfig
  //
  // Load the group configuration file
  //
  void Group::LoadConfig()
  {
    FilePath configPath;
    PTree pTree;

    // Generate the config name
    Dir::PathMake(configPath, GetPath().str, MISSIONS_FILE_GROUP);
 
    // Add the campaign config
    if (pTree.AddFile(configPath.str))
    {
      FScope *gScope = pTree.GetGlobalScope();
      FScope *sScope;

      // Process each function
      while ((sScope = gScope->NextFunction()) != NULL)
      {
        switch (sScope->NameCrc())
        {
          case 0x47CB37F2: // "Description"
            description = StdLoad::TypeString(sScope);
            break;

          case 0xF81D1051: // "System"
            system = StdLoad::TypeU32(sScope);
            break;

          case 0xC2B3BE7B: // "InstantAction"
            instantAction = StdLoad::TypeU32(sScope);
            break;

          case 0x7BB50683: // "Campaign"
            Campaigns::CreateCampaign(*this, sScope);
            break;
        }
      }
    }
  }
Ejemplo n.º 30
0
bool read_ini(const std::string & file_name, const file_open & fopen, PTree & p)
{
	p.value() = file_name;
	std::istream * in = fopen(file_name);
	if (in->good())
	{
		ini reader(*in, p, &fopen);
		reader.read();
		delete in;
		return true;
	}
	delete in;
	return false;
}