mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-02 00:42:33 +01:00
Replacing "new" operators with make_unique/shared (#306)
* Replace "new" operator with std::make_unique for BS in BinaryStream.cpp * Replace "new" operator with std::make_unique for textureArchive in TextureArchive.cpp * Replace "new" operator with std::make_unique for variables in LoaderIDE.cpp * Addition constructor for InstanceData * Replace "new" operator with std::make_shared for instance in LoaderIPL.cpp
This commit is contained in:
parent
b7ae0a54e4
commit
8b067f4f69
@ -20,7 +20,7 @@ std::unique_ptr<BinaryStream> BinaryStream::parse(const std::string &filename) {
|
||||
dfile.read(data, length);
|
||||
// std::cout << "File is " << length << " bytes" << std::endl << std::endl;
|
||||
|
||||
auto BS = std::unique_ptr<BinaryStream>(new BinaryStream);
|
||||
auto BS = std::make_unique<BinaryStream>();
|
||||
|
||||
// Set file's ACTUAL length
|
||||
auto header = reinterpret_cast<nativeSectionHeader_t *>(data);
|
||||
|
@ -8,7 +8,7 @@ namespace RW {
|
||||
|
||||
std::unique_ptr<TextureArchive> TextureArchive::create(
|
||||
BinaryStream &binaryStream) {
|
||||
auto textureArchive = std::unique_ptr<TextureArchive>(new TextureArchive);
|
||||
auto textureArchive = std::make_unique<TextureArchive>();
|
||||
|
||||
auto section = binaryStream.rootHeader;
|
||||
|
||||
|
@ -26,6 +26,17 @@ struct InstanceData {
|
||||
* Instance rotation
|
||||
*/
|
||||
glm::quat rot;
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
InstanceData(int _id, std::string _model, glm::vec3 _pos, glm::vec3 _scale, glm::quat _rot)
|
||||
: id(_id)
|
||||
, model(_model)
|
||||
, pos(_pos)
|
||||
, scale(_scale)
|
||||
, rot(_rot){
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -65,8 +65,7 @@ bool LoaderIDE::load(const std::string &filename, const PedStatsList &stats) {
|
||||
break;
|
||||
case OBJS:
|
||||
case TOBJ: { // Supports Type 1, 2 and 3
|
||||
auto objs =
|
||||
std::unique_ptr<SimpleModelInfo>(new SimpleModelInfo);
|
||||
auto objs = std::make_unique<SimpleModelInfo>();
|
||||
|
||||
getline(strstream, buff, ',');
|
||||
objs->setModelID(atoi(buff.c_str()));
|
||||
@ -102,8 +101,7 @@ bool LoaderIDE::load(const std::string &filename, const PedStatsList &stats) {
|
||||
break;
|
||||
}
|
||||
case CARS: {
|
||||
auto cars =
|
||||
std::unique_ptr<VehicleModelInfo>(new VehicleModelInfo);
|
||||
auto cars = std::make_unique<VehicleModelInfo>();
|
||||
|
||||
getline(strstream, buff, ',');
|
||||
cars->setModelID(std::atoi(buff.c_str()));
|
||||
@ -150,7 +148,7 @@ bool LoaderIDE::load(const std::string &filename, const PedStatsList &stats) {
|
||||
break;
|
||||
}
|
||||
case PEDS: {
|
||||
auto peds = std::unique_ptr<PedModelInfo>(new PedModelInfo);
|
||||
auto peds = std::make_unique<PedModelInfo>();
|
||||
|
||||
getline(strstream, buff, ',');
|
||||
peds->setModelID(std::atoi(buff.c_str()));
|
||||
@ -246,8 +244,7 @@ bool LoaderIDE::load(const std::string &filename, const PedStatsList &stats) {
|
||||
break;
|
||||
}
|
||||
case HIER: {
|
||||
auto hier =
|
||||
std::unique_ptr<ClumpModelInfo>(new ClumpModelInfo);
|
||||
auto hier = std::make_unique<ClumpModelInfo>();
|
||||
|
||||
getline(strstream, buff, ',');
|
||||
hier->setModelID(std::atoi(buff.c_str()));
|
||||
|
@ -68,7 +68,7 @@ bool LoaderIPL::load(const std::string& filename) {
|
||||
getline(strstream, rotZ, ',');
|
||||
getline(strstream, rotW, ',');
|
||||
|
||||
std::shared_ptr<InstanceData> instance(new InstanceData{
|
||||
auto instance = std::make_shared<InstanceData>(
|
||||
atoi(id.c_str()), // ID
|
||||
model.substr(1, model.size() - 1),
|
||||
glm::vec3(atof(posX.c_str()), atof(posY.c_str()),
|
||||
@ -77,7 +77,7 @@ bool LoaderIPL::load(const std::string& filename) {
|
||||
atof(scaleZ.c_str())),
|
||||
glm::normalize(
|
||||
glm::quat(-atof(rotW.c_str()), atof(rotX.c_str()),
|
||||
atof(rotY.c_str()), atof(rotZ.c_str())))});
|
||||
atof(rotY.c_str()), atof(rotZ.c_str()))));
|
||||
|
||||
m_instances.push_back(instance);
|
||||
} else if (section == ZONE) {
|
||||
|
Loading…
Reference in New Issue
Block a user