mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-25 20:02:40 +01:00
cast_to_float
This commit is contained in:
parent
da7e54b64a
commit
b2c2075be7
@ -340,11 +340,11 @@ void GameData::loadWater(const std::string& path) {
|
||||
std::getline(ss, e, ',')) {
|
||||
|
||||
waterBlocks.emplace_back(
|
||||
atof(a.c_str()),
|
||||
atof(b.c_str()),
|
||||
atof(c.c_str()),
|
||||
atof(d.c_str()),
|
||||
atof(e.c_str()));
|
||||
lexical_cast<float>(a),
|
||||
lexical_cast<float>(b),
|
||||
lexical_cast<float>(c),
|
||||
lexical_cast<float>(d),
|
||||
lexical_cast<float>(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ bool LoaderIDE::load(const std::string &filename, const PedStatsList &stats) {
|
||||
|
||||
for (int i = 0; i < objs->getNumAtomics(); i++) {
|
||||
getline(strstream, buff, ',');
|
||||
objs->setLodDistance(i, atof(buff.c_str()));
|
||||
objs->setLodDistance(i, lexical_cast<float>(buff));
|
||||
}
|
||||
|
||||
objs->determineFurthest();
|
||||
@ -138,7 +138,7 @@ bool LoaderIDE::load(const std::string &filename, const PedStatsList &stats) {
|
||||
getline(strstream, buff, ',');
|
||||
cars->wheelmodel_ = lexical_cast<int>(buff);
|
||||
getline(strstream, buff, ',');
|
||||
cars->wheelscale_ = std::atof(buff.c_str());
|
||||
cars->wheelscale_ = lexical_cast<float>(buff);
|
||||
break;
|
||||
case VehicleModelInfo::PLANE:
|
||||
/// @todo load LOD
|
||||
@ -222,16 +222,16 @@ bool LoaderIDE::load(const std::string &filename, const PedStatsList &stats) {
|
||||
getline(buffstream, buff, ','); // "Always 0"
|
||||
|
||||
getline(buffstream, buff, ',');
|
||||
node.position.x = strtof(buff.c_str(), nullptr) / 16.f;
|
||||
node.position.x = lexical_cast<float>(buff) / 16.f;
|
||||
|
||||
getline(buffstream, buff, ',');
|
||||
node.position.y = strtof(buff.c_str(), nullptr) / 16.f;
|
||||
node.position.y = lexical_cast<float>(buff) / 16.f;
|
||||
|
||||
getline(buffstream, buff, ',');
|
||||
node.position.z = strtof(buff.c_str(), nullptr) / 16.f;
|
||||
node.position.z = lexical_cast<float>(buff) / 16.f;
|
||||
|
||||
getline(buffstream, buff, ',');
|
||||
node.size = strtof(buff.c_str(), nullptr) / 16.f;
|
||||
node.size = lexical_cast<float>(buff) / 16.f;
|
||||
|
||||
getline(buffstream, buff, ',');
|
||||
node.leftLanes = lexical_cast<int>(buff);
|
||||
|
@ -80,13 +80,13 @@ bool LoaderIPL::load(const std::string& filename) {
|
||||
auto instance = std::make_shared<InstanceData>(
|
||||
lexical_cast<int>(id), // ID
|
||||
model.substr(1, model.size() - 1),
|
||||
glm::vec3(atof(posX.c_str()), atof(posY.c_str()),
|
||||
atof(posZ.c_str())),
|
||||
glm::vec3(atof(scaleX.c_str()), atof(scaleY.c_str()),
|
||||
atof(scaleZ.c_str())),
|
||||
glm::vec3(lexical_cast<float>(posX), lexical_cast<float>(posY),
|
||||
lexical_cast<float>(posZ)),
|
||||
glm::vec3(lexical_cast<float>(scaleX), lexical_cast<float>(scaleY),
|
||||
lexical_cast<float>(scaleZ)),
|
||||
glm::normalize(
|
||||
glm::quat(-atof(rotW.c_str()), atof(rotX.c_str()),
|
||||
atof(rotY.c_str()), atof(rotZ.c_str()))));
|
||||
glm::quat(-lexical_cast<float>(rotW), lexical_cast<float>(rotX),
|
||||
lexical_cast<float>(rotY), lexical_cast<float>(rotZ))));
|
||||
|
||||
m_instances.push_back(instance);
|
||||
} else if (section == ZONE) {
|
||||
@ -103,18 +103,18 @@ bool LoaderIPL::load(const std::string& filename) {
|
||||
zone.type = lexical_cast<int>(value);
|
||||
|
||||
getline(strstream, value, ',');
|
||||
zone.min.x = atof(value.c_str());
|
||||
zone.min.x = lexical_cast<float>(value);
|
||||
getline(strstream, value, ',');
|
||||
zone.min.y = atof(value.c_str());
|
||||
zone.min.y = lexical_cast<float>(value);
|
||||
getline(strstream, value, ',');
|
||||
zone.min.z = atof(value.c_str());
|
||||
zone.min.z = lexical_cast<float>(value);
|
||||
|
||||
getline(strstream, value, ',');
|
||||
zone.max.x = atof(value.c_str());
|
||||
zone.max.x = lexical_cast<float>(value);
|
||||
getline(strstream, value, ',');
|
||||
zone.max.y = atof(value.c_str());
|
||||
zone.max.y = lexical_cast<float>(value);
|
||||
getline(strstream, value, ',');
|
||||
zone.max.z = atof(value.c_str());
|
||||
zone.max.z = lexical_cast<float>(value);
|
||||
|
||||
getline(strstream, value, ',');
|
||||
zone.island = lexical_cast<int>(value);
|
||||
|
@ -24,4 +24,12 @@ inline int lexical_cast(const std::string& source) {
|
||||
return result;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline float lexical_cast(const std::string& source) {
|
||||
char* end = nullptr; //for errors handling
|
||||
float result = std::strtof(source.c_str(), &end);
|
||||
RW_CHECK(end != source.c_str(), "Problem with conversion " << *end << " to float");
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user