1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-25 03:42:48 +01:00

Helper argument to clone Atomics with a new frame

This commit is contained in:
Daniel Evans 2019-05-15 23:28:09 +01:00
parent 77b405b7c5
commit 86bf69b0a0
5 changed files with 7 additions and 16 deletions

View File

@ -82,10 +82,10 @@ ModelFramePtr ModelFrame::cloneHierarchy() const {
return self;
}
AtomicPtr Atomic::clone() const {
AtomicPtr Atomic::clone(const ModelFramePtr& newFrame) const {
auto newatomic = std::make_shared<Atomic>();
newatomic->setGeometry(getGeometry());
newatomic->setFrame(getFrame());
newatomic->setFrame(newFrame ? newFrame : getFrame());
newatomic->setFlags(getFlags());
return newatomic;
}

View File

@ -234,7 +234,7 @@ public:
}
}
AtomicPtr clone() const;
AtomicPtr clone(const ModelFramePtr& newFrame = {}) const;
};
/**

View File

@ -165,13 +165,8 @@ void InstanceObject::changeModel(BaseModelInfo* incoming, int atomicNumber) {
atomicNumber);
auto atomic = getModelInfo<SimpleModelInfo>()->getAtomic(atomicNumber);
if (atomic) {
auto previous = atomic_;
atomic_ = atomic->clone();
if (previous) {
atomic_->setFrame(previous->getFrame());
} else {
atomic_->setFrame(std::make_shared<ModelFrame>());
}
const auto frame = atomic_ ? atomic_->getFrame() : std::make_shared<ModelFrame>();
atomic_ = atomic->clone(frame);
}
if (collision) {

View File

@ -273,9 +273,7 @@ PickupObject::PickupObject(GameWorld* world, const glm::vec3& position,
setCollected(false);
auto modelData = getModelInfo<SimpleModelInfo>();
auto atomic = modelData->getAtomic(0)->clone();
atomic->setFrame(std::make_shared<ModelFrame>());
setModel(std::move(atomic));
setModel(modelData->getAtomic(0)->clone(std::make_shared<ModelFrame>()));
updateTransform(getPosition(), getRotation());
}

View File

@ -163,9 +163,7 @@ ProjectileObject::ProjectileObject(GameWorld* world, const glm::vec3& position,
const auto& modelData = world->data->findModelInfo<SimpleModelInfo>(
getProjectileInfo().weapon->modelID);
auto atomic = modelData->getAtomic(0)->clone();
atomic->setFrame(std::make_shared<ModelFrame>());
setModel(std::move(atomic));
setModel(modelData->getAtomic(0)->clone(std::make_shared<ModelFrame>()));
}
ProjectileObject::~ProjectileObject() {