本文整理汇总了C++中PTree::get方法的典型用法代码示例。如果您正苦于以下问题:C++ PTree::get方法的具体用法?C++ PTree::get怎么用?C++ PTree::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PTree
的用法示例。
在下文中一共展示了PTree::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: name
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))
{
}
示例2: operator
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);
}
示例3: LoadCoilover
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;
}
示例4: LoadCameras
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;
}
示例5: LoadPhysics
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;
}
示例6: read
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);
}
}
示例7: LoadLight
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;
}
示例8: LoadLight
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;
}
示例9: LoadPoints
// 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]);
}
}
示例10: operator
bool operator()(const PTree & cfg)
{
const PTree * link;
if (cfg.get("link", link))
{
// load breakable body drawables
if (!loadDrawable(cfg, topnode)) return false;
}
else
{
// load fixed body drawables
if (!loadDrawable(cfg, topnode.GetNode(bodynode))) return false;
}
return true;
}
示例11: Load
bool CARENGINEINFO::Load(const PTree & cfg, std::ostream & error_output)
{
std::vector<std::pair<btScalar, btScalar> > torque;
std::vector<btScalar> pos(3);
if (!cfg.get("peak-engine-rpm", redline, error_output)) return false; //used only for the redline graphics
if (!cfg.get("rpm-limit", rpm_limit, error_output)) return false;
if (!cfg.get("inertia", inertia, error_output)) return false;
if (!cfg.get("start-rpm", start_rpm, error_output)) return false;
if (!cfg.get("stall-rpm", stall_rpm, error_output)) return false;
if (!cfg.get("fuel-consumption", fuel_consumption, error_output)) return false;
if (!cfg.get("mass", mass, error_output)) return false;
if (!cfg.get("position", pos, error_output)) return false;
position.setValue(pos[0], pos[1], pos[2]);
int curve_num = 0;
std::vector<btScalar> torque_point(2);
std::string torque_str("torque-curve-00");
while (cfg.get(torque_str, torque_point))
{
torque.push_back(std::pair<btScalar, btScalar>(torque_point[0], torque_point[1]));
curve_num++;
std::stringstream str;
str << "torque-curve-";
str.width(2);
str.fill('0');
str << curve_num;
torque_str = str.str();
}
if (torque.size() <= 1)
{
error_output << "You must define at least 2 torque curve points." << std::endl;
return false;
}
SetTorqueCurve(redline, torque);
return true;
}
示例12: Load
bool CarGraphics::Load(
const PTree & cfg,
const std::string & carpath,
const std::string & /*carname*/,
const std::string & carwheel,
const std::string & carpaint,
const Vec3 & carcolor,
const int anisotropy,
const float camerabounce,
ContentManager & content,
std::ostream & error_output)
{
assert(!loaded);
// init drawable load functor
LoadDrawable loadDrawable(carpath, anisotropy, content, models, textures, error_output);
// load body first
const PTree * cfg_body;
std::string meshname;
std::vector<std::string> texname;
if (!cfg.get("body", cfg_body, error_output)) return false;
if (!cfg_body->get("mesh", meshname, error_output)) return false;
if (!cfg_body->get("texture", texname, error_output)) return false;
if (carpaint != "default") texname[0] = carpaint;
if (!loadDrawable(meshname, texname, *cfg_body, topnode, &bodynode)) return false;
// load wheels
const PTree * cfg_wheels;
if (!cfg.get("wheel", cfg_wheels, error_output)) return false;
std::shared_ptr<PTree> sel_wheel;
if (carwheel != "default" && !content.load(sel_wheel, carpath, carwheel)) return false;
for (PTree::const_iterator i = cfg_wheels->begin(); i != cfg_wheels->end(); ++i)
{
const PTree * cfg_wheel = &i->second;
// override default wheel with selected, not very efficient, fixme
PTree opt_wheel;
if (sel_wheel.get())
{
opt_wheel.set(*sel_wheel);
opt_wheel.merge(*cfg_wheel);
cfg_wheel = &opt_wheel;
}
if (!LoadWheel(*cfg_wheel, loadDrawable, topnode, error_output))
{
error_output << "Failed to load wheels." << std::endl;
return false;
}
}
// load drawables
LoadBody loadBody(topnode, bodynode, loadDrawable);
for (PTree::const_iterator i = cfg.begin(); i != cfg.end(); ++i)
{
if (i->first != "body" &&
i->first != "steering" &&
i->first != "light-brake" &&
i->first != "light-reverse")
{
loadBody(i->second);
}
}
// load steering wheel
const PTree * cfg_steer;
if (cfg.get("steering", cfg_steer))
{
SceneNode & bodynoderef = topnode.GetNode(bodynode);
if (!loadDrawable(*cfg_steer, bodynoderef, &steernode, 0))
{
error_output << "Failed to load steering wheel." << std::endl;
return false;
}
cfg_steer->get("max-angle", steer_angle_max);
steer_angle_max = steer_angle_max / 180.0 * M_PI;
SceneNode & steernoderef = bodynoderef.GetNode(steernode);
steer_orientation = steernoderef.GetTransform().GetRotation();
steer_rotation = steer_orientation;
}
// load brake/reverse light point light sources (optional)
int i = 0;
std::string istr = "0";
const PTree * cfg_light;
while (cfg.get("light-brake-"+istr, cfg_light))
{
if (!LoadLight(*cfg_light, content, error_output))
{
error_output << "Failed to load lights." << std::endl;
return false;
}
std::ostringstream sstr;
sstr << ++i;
istr = sstr.str();
}
//.........这里部分代码省略.........
示例13: LoadGraphics
bool CAR::LoadGraphics(
const PTree & cfg,
const std::string & partspath,
const std::string & carpath,
const std::string & carname,
const std::string & carpaint,
const MATHVECTOR <float, 3> & carcolor,
const int anisotropy,
const float camerabounce,
const bool damage,
const bool debugmode,
ContentManager & content,
std::ostream & info_output,
std::ostream & error_output)
{
//write_inf(cfg, std::cerr);
cartype = carname;
LoadDrawable loadDrawable(carpath, anisotropy, content, models, error_output);
// load body first
const PTree * cfg_body;
std::string meshname;
std::vector<std::string> texname;
if (!cfg.get("body", cfg_body, error_output))
{
error_output << "there is a problem with the .car file" << std::endl;
return false;
}
if (!cfg_body->get("mesh", meshname, error_output)) return false;
if (!cfg_body->get("texture", texname, error_output)) return false;
if (carpaint != "default") texname[0] = carpaint;
if (!loadDrawable(meshname, texname, *cfg_body, topnode, &bodynode)) return false;
// load wheels
const PTree * cfg_wheel;
if (!cfg.get("wheel", cfg_wheel, error_output)) return false;
for (PTree::const_iterator i = cfg_wheel->begin(); i != cfg_wheel->end(); ++i)
{
if (!LoadWheel(i->second, loadDrawable, topnode, error_output))
{
error_output << "Failed to load wheels." << std::endl;
return false;
}
}
// load drawables
LoadBody loadBody(topnode, bodynode, loadDrawable);
for (PTree::const_iterator i = cfg.begin(); i != cfg.end(); ++i)
{
if (i->first != "body" &&
i->first != "steering" &&
i->first != "light-brake" &&
i->first != "light-reverse")
{
loadBody(i->second);
}
}
// load steering wheel
const PTree * cfg_steer;
if (cfg.get("steering", cfg_steer))
{
SCENENODE & bodynoderef = topnode.GetNode(bodynode);
if (!loadDrawable(*cfg_steer, bodynoderef, &steernode, 0))
{
error_output << "Failed to load steering wheel." << std::endl;
return false;
}
cfg_steer->get("max-angle", steer_angle_max);
steer_angle_max = steer_angle_max / 180.0 * M_PI;
SCENENODE & steernoderef = bodynoderef.GetNode(steernode);
steer_orientation = steernoderef.GetTransform().GetRotation();
}
// load brake/reverse light point light sources (optional)
int i = 0;
std::string istr = "0";
const PTree * cfg_light;
while (cfg.get("light-brake-"+istr, cfg_light))
{
if (!LoadLight(*cfg_light, content, error_output))
{
error_output << "Failed to load lights." << std::endl;
return false;
}
std::stringstream sstr;
sstr << ++i;
istr = sstr.str();
}
i = 0;
istr = "0";
while (cfg.get("light-reverse-"+istr, cfg_light))
{
if (!LoadLight(*cfg_light, content, error_output))
{
error_output << "Failed to load lights." << std::endl;
return false;
}
//.........这里部分代码省略.........
示例14: Load
bool CarSuspension::Load(
const PTree & cfg_wheel,
CarSuspension *& suspension,
std::ostream & error_output)
{
CarSuspensionInfo info;
std::vector<btScalar> p(3);
if (!cfg_wheel.get("position", p, error_output)) return false;
if (!cfg_wheel.get("camber", info.camber, error_output)) return false;
if (!cfg_wheel.get("caster", info.caster, error_output)) return false;
if (!cfg_wheel.get("toe", info.toe, error_output)) return false;
cfg_wheel.get("steering", info.steering_angle);
cfg_wheel.get("ackermann", info.ackermann);
info.position.setValue(p[0], p[1], p[2]);
const PTree * cfg_coil;
if (!cfg_wheel.get("coilover", cfg_coil, error_output)) return false;
if (!LoadCoilover(*cfg_coil, info, error_output)) return false;
const PTree * cfg_susp;
if (cfg_wheel.get("macpherson-strut", cfg_susp))
{
std::vector<btScalar> strut_top(3), strut_end(3), hinge(3);
if (!cfg_susp->get("hinge", hinge, error_output)) return false;
if (!cfg_susp->get("strut-top", strut_top, error_output)) return false;
if (!cfg_susp->get("strut-end", strut_end, error_output)) return false;
MacPhersonSuspension * mps = new MacPhersonSuspension();
mps->Init(info, strut_top, strut_end, hinge);
suspension = mps;
}
/* else if (cfg_wheel.get("double-wishbone", cfg_susp))
{
std::vector<btScalar> up_ch0(3), up_ch1(3), lo_ch0(3), lo_ch1(3), up_hub(3), lo_hub(3);
if (!cfg_susp->get("upper-chassis-front", up_ch0, error_output)) return false;
if (!cfg_susp->get("upper-chassis-rear", up_ch1, error_output)) return false;
if (!cfg_susp->get("lower-chassis-front", lo_ch0, error_output)) return false;
if (!cfg_susp->get("lower-chassis-rear", lo_ch1, error_output)) return false;
if (!cfg_susp->get("upper-hub", up_hub, error_output)) return false;
if (!cfg_susp->get("lower-hub", lo_hub, error_output)) return false;
WishboneSuspension * wbs = new WishboneSuspension();
wbs->Init(info, up_ch0, up_ch1, lo_ch0, lo_ch1, up_hub, lo_hub);
suspension = wbs;
}*/
else
{
std::vector<btScalar> ch(3, 0), wh(3, 0);
if (!cfg_wheel.get("hinge", cfg_susp, error_output)) return false;
if (!cfg_susp->get("chassis", ch, error_output)) return false;
if (!cfg_susp->get("wheel", wh, error_output)) return false;
BasicSuspension * bs = new BasicSuspension();
bs->Init(info, ch, wh);
suspension = bs;
}
return true;
}
示例15: LoadWheel
static bool LoadWheel(
const PTree & cfg_wheel,
struct LoadDrawable & loadDrawable,
SceneNode & topnode,
std::ostream & error_output)
{
SceneNode::Handle wheelnode = topnode.AddNode();
ContentManager & content = loadDrawable.content;
const std::string& path = loadDrawable.path;
std::string meshname;
std::vector<std::string> texname;
std::shared_ptr<Model> mesh;
const PTree * cfg_tire;
Vec3 size(0);
std::string sizestr;
if (!cfg_wheel.get("mesh", meshname, error_output)) return false;
if (!cfg_wheel.get("texture", texname, error_output)) return false;
if (!cfg_wheel.get("tire", cfg_tire, error_output)) return false;
if (!cfg_tire->get("size", sizestr, error_output)) return false;
if (!cfg_tire->get("size", size, error_output)) return false;
// load wheel
bool genrim = true;
cfg_wheel.get("genrim", genrim);
if (genrim)
{
// get wheel disk mesh
content.load(mesh, path, meshname);
// gen wheel mesh
meshname = meshname + sizestr;
if (!content.get(mesh, path, meshname))
{
float width = size[0] * 0.001;
float diameter = size[2] * 0.0254;
VertexArray rimva, diskva;
MeshGen::mg_rim(rimva, size[0], size[1], size[2], 10);
diskva = mesh->GetVertexArray();
diskva.Translate(-0.75 * 0.5, 0, 0);
diskva.Scale(width, diameter, diameter);
content.load(mesh, path, meshname, rimva + diskva);
}
}
if (!loadDrawable(meshname, texname, cfg_wheel, topnode, &wheelnode))
{
return false;
}
// load tire (optional)
texname.clear();
if (cfg_tire->get("texture", texname))
{
meshname.clear();
if (!cfg_tire->get("mesh", meshname))
{
// gen tire mesh
meshname = "tire" + sizestr;
if (!content.get(mesh, path, meshname))
{
VertexArray tireva;
MeshGen::mg_tire(tireva, size[0], size[1], size[2]);
content.load(mesh, path, meshname, tireva);
}
}
if (!loadDrawable(meshname, texname, *cfg_tire, topnode.GetNode(wheelnode)))
{
return false;
}
}
// load brake (optional)
texname.clear();
const PTree * cfg_brake;
if (cfg_wheel.get("brake", cfg_brake, error_output) &&
cfg_brake->get("texture", texname))
{
float radius;
std::string radiusstr;
cfg_brake->get("radius", radius);
cfg_brake->get("radius", radiusstr);
meshname.clear();
if (!cfg_brake->get("mesh", meshname))
{
// gen brake disk mesh
meshname = "brake" + radiusstr;
if (!content.get(mesh, path, meshname))
{
float diameter_mm = radius * 2 * 1000;
float thickness_mm = 0.025 * 1000;
VertexArray brakeva;
MeshGen::mg_brake_rotor(brakeva, diameter_mm, thickness_mm);
content.load(mesh, path, meshname, brakeva);
}
}
//.........这里部分代码省略.........