Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Source/Entities/ACrab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ int ACrab::Create(const ACrab& reference) {
m_BackupRBGFootGroup->SetLimbPos(atomGroupToUseAsFootGroupLFG->GetLimbPos());

if (reference.m_StrideSound) {
m_StrideSound = dynamic_cast<SoundContainer*>(reference.m_StrideSound->Clone());
m_StrideSound = std::make_shared<SoundContainer>();
reference.m_StrideSound->Clone(&*m_StrideSound);
}

m_MovementState = reference.m_MovementState;
Expand Down Expand Up @@ -297,8 +298,8 @@ int ACrab::ReadProperty(const std::string_view& propName, Reader& reader) {
m_BackupRBGFootGroup->RemoveAllAtoms();
});
MatchProperty("StrideSound", {
m_StrideSound = new SoundContainer;
reader >> m_StrideSound;
m_StrideSound = std::make_shared<SoundContainer>();
reader >> *m_StrideSound;
});
MatchForwards("LStandLimbPath") MatchProperty("LeftStandLimbPath", { reader >> m_Paths[LEFTSIDE][FGROUND][STAND]; });
MatchForwards("LWalkLimbPath") MatchProperty("LeftWalkLimbPath", { reader >> m_Paths[LEFTSIDE][FGROUND][WALK]; });
Expand Down Expand Up @@ -337,7 +338,7 @@ int ACrab::Save(Writer& writer) const {
writer.NewProperty("RBGFootGroup");
writer << m_pRBGFootGroup;
writer.NewProperty("StrideSound");
writer << m_StrideSound;
writer << *m_StrideSound;

writer.NewProperty("LStandLimbPath");
writer << m_Paths[LEFTSIDE][FGROUND][STAND];
Expand Down Expand Up @@ -368,7 +369,6 @@ void ACrab::Destroy(bool notInherited) {
delete m_pRFGFootGroup;
delete m_pRBGFootGroup;

delete m_StrideSound;
// for (deque<LimbPath *>::iterator itr = m_WalkPaths.begin();
// itr != m_WalkPaths.end(); ++itr)
// delete *itr;
Expand Down
20 changes: 13 additions & 7 deletions Source/Entities/ACrab.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Actor.h"
#include "LimbPath.h"
#include "Leg.h"
#include <memory>

struct BITMAP;

Expand Down Expand Up @@ -243,13 +244,18 @@ namespace RTE {
/// @param newForce New push force value in kg * m/s^2.
void SetLimbPathPushForce(MovementState movementState, float newForce);

/// Gets this ACrab's stride sound. Ownership is NOT transferred!
/// Gets this ACrab's stride sound.
/// @return The SoundContainer for this ACrab's stride sound.
SoundContainer* GetStrideSound() const { return m_StrideSound; }

/// Sets this ACrab's stride sound. Ownership IS transferred!
/// @param newSound The new SoundContainer for this ACrab's stride sound.
void SetStrideSound(SoundContainer* newSound) { m_StrideSound = newSound; }
std::shared_ptr<SoundContainer> GetStrideSound() const { return m_StrideSound; }

/// Sets this ACrab's stride sound to a copy of the input.
/// @param newSound The new SoundContainer for this ACrab's stride sound to copy.
void SetStrideSound(const SoundContainer* newSound) {
if (!newSound)
m_StrideSound = nullptr;
else
m_StrideSound = std::make_shared<SoundContainer>(*newSound);
}

/// Gets the upper limit of this ACrab's aim range.
/// @return The upper limit of this ACrab's aim range.
Expand Down Expand Up @@ -301,7 +307,7 @@ namespace RTE {
AtomGroup* m_pRBGFootGroup;
AtomGroup* m_BackupRBGFootGroup;
// The sound of the actor taking a step (think robot servo)
SoundContainer* m_StrideSound;
std::shared_ptr<SoundContainer> m_StrideSound;
// Jetpack booster.
AEJetpack* m_pJetpack;
// Blink timer
Expand Down
34 changes: 17 additions & 17 deletions Source/Entities/ACraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,15 @@ int ACraft::Create(const ACraft& reference) {
m_HatchState = reference.m_HatchState;
m_HatchDelay = reference.m_HatchDelay;
if (reference.m_HatchOpenSound) {
m_HatchOpenSound = dynamic_cast<SoundContainer*>(reference.m_HatchOpenSound->Clone());
m_HatchOpenSound = std::make_shared<SoundContainer>();
reference.m_HatchOpenSound->Clone(&*m_HatchOpenSound);
}
if (reference.m_HatchCloseSound) {
m_HatchCloseSound = dynamic_cast<SoundContainer*>(reference.m_HatchCloseSound->Clone());
m_HatchCloseSound = std::make_shared<SoundContainer>();
reference.m_HatchCloseSound->Clone(&*m_HatchCloseSound);
} else if (reference.m_HatchOpenSound) {
m_HatchCloseSound = dynamic_cast<SoundContainer*>(reference.m_HatchOpenSound->Clone());
m_HatchCloseSound = std::make_shared<SoundContainer>();
reference.m_HatchOpenSound->Clone(&*m_HatchCloseSound);
}
for (std::deque<MovableObject*>::const_iterator niItr = reference.m_CollectedInventory.begin(); niItr != reference.m_CollectedInventory.end(); ++niItr)
m_CollectedInventory.push_back(dynamic_cast<MovableObject*>((*niItr)->Clone()));
Expand All @@ -246,7 +249,8 @@ int ACraft::Create(const ACraft& reference) {
m_HasDelivered = reference.m_HasDelivered;
m_LandingCraft = reference.m_LandingCraft;
if (reference.m_CrashSound) {
m_CrashSound = dynamic_cast<SoundContainer*>(reference.m_CrashSound->Clone());
m_CrashSound = std::make_shared<SoundContainer>();
reference.m_CrashSound->Clone(&*m_CrashSound);
}

m_DeliveryState = reference.m_DeliveryState;
Expand All @@ -267,16 +271,16 @@ int ACraft::ReadProperty(const std::string_view& propName, Reader& reader) {

MatchProperty("HatchDelay", { reader >> m_HatchDelay; });
MatchProperty("HatchOpenSound", {
m_HatchOpenSound = new SoundContainer;
reader >> m_HatchOpenSound;
m_HatchOpenSound = std::make_shared<SoundContainer>();
reader >> *m_HatchOpenSound;
});
MatchProperty("HatchCloseSound", {
m_HatchCloseSound = new SoundContainer;
reader >> m_HatchCloseSound;
m_HatchCloseSound = std::make_shared<SoundContainer>();
reader >> *m_HatchCloseSound;
});
MatchProperty("CrashSound", {
m_CrashSound = new SoundContainer;
reader >> m_CrashSound;
m_CrashSound = std::make_shared<SoundContainer>();
reader >> *m_CrashSound;
});
MatchProperty("AddExit",
{
Expand All @@ -301,9 +305,9 @@ int ACraft::Save(Writer& writer) const {
writer.NewProperty("HatchDelay");
writer << m_HatchDelay;
writer.NewProperty("HatchOpenSound");
writer << m_HatchOpenSound;
writer << *m_HatchOpenSound;
writer.NewProperty("HatchCloseSound");
writer << m_HatchCloseSound;
writer << *m_HatchCloseSound;
for (std::list<Exit>::const_iterator itr = m_Exits.begin(); itr != m_Exits.end(); ++itr) {
writer.NewProperty("AddExit");
writer << (*itr);
Expand All @@ -316,7 +320,7 @@ int ACraft::Save(Writer& writer) const {
writer << m_LandingCraft;

writer.NewProperty("CrashSound");
writer << m_CrashSound;
writer << *m_CrashSound;

writer.NewProperty("CanEnterOrbit");
writer << m_CanEnterOrbit;
Expand All @@ -332,10 +336,6 @@ int ACraft::Save(Writer& writer) const {
}

void ACraft::Destroy(bool notInherited) {
delete m_HatchOpenSound;
delete m_HatchCloseSound;
delete m_CrashSound;

if (!notInherited)
Actor::Destroy();
Clear();
Expand Down
58 changes: 37 additions & 21 deletions Source/Entities/ACraft.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/// Inclusions of header files
#include "Actor.h"
#include "LimbPath.h"
#include <memory>

struct BITMAP;

Expand Down Expand Up @@ -305,29 +306,44 @@ namespace RTE {
/// @param movableObjectToIgnore A pointer to an MO which the Gibs and Attachables should not be colliding with.
void GibThis(const Vector& impactImpulse = Vector(), MovableObject* movableObjectToIgnore = nullptr) override;

/// Gets this ACraft's hatch opening sound. Ownership is NOT transferred!
/// Gets this ACraft's hatch opening sound.
/// @return The SoundContainer for this ACraft's hatch opening sound.
SoundContainer* GetHatchOpenSound() const { return m_HatchOpenSound; }

/// Sets this ACraft's hatch opening sound. Ownership IS transferred!
/// @param newSound The new SoundContainer for this ACraft's hatch opening sound.
void SetHatchOpenSound(SoundContainer* newSound) { m_HatchOpenSound = newSound; }
std::shared_ptr<SoundContainer> GetHatchOpenSound() const { return m_HatchOpenSound; }

/// Sets this ACraft's hatch opening sound to a copy of the input.
/// @param newSound The new SoundContainer for this ACraft's hatch opening sound to copy.
void SetHatchOpenSound(const SoundContainer* newSound) {
if (!newSound)
m_HatchOpenSound = nullptr;
else
m_HatchOpenSound = std::make_shared<SoundContainer>(*newSound);
}

/// Gets this ACraft's hatch closing sound. Ownership is NOT transferred!
/// Gets this ACraft's hatch closing sound.
/// @return The SoundContainer for this ACraft's hatch closing sound.
SoundContainer* GetHatchCloseSound() const { return m_HatchCloseSound; }

/// Sets this ACraft's hatch closing sound. Ownership IS transferred!
/// @param newSound The new SoundContainer for this ACraft's hatch closing sound.
void SetHatchCloseSound(SoundContainer* newSound) { m_HatchCloseSound = newSound; }
std::shared_ptr<SoundContainer> GetHatchCloseSound() const { return m_HatchCloseSound; }

/// Sets this ACraft's hatch closing sound to a copy of the input.
/// @param newSound The new SoundContainer for this ACraft's hatch closing sound to copy.
void SetHatchCloseSound(const SoundContainer* newSound) {
if (!newSound)
m_HatchCloseSound = nullptr;
else
m_HatchCloseSound = std::make_shared<SoundContainer>(*newSound);
}

/// Gets this ACraft's crash sound. Ownership is NOT transferred!
/// Gets this ACraft's crash sound.
/// @return The SoundContainer for this ACraft's crash sound.
SoundContainer* GetCrashSound() const { return m_CrashSound; }

/// Sets this ACraft's crash sound. Ownership IS transferred!
/// @param newSound The new SoundContainer for this ACraft's crash sound.
void SetCrashSound(SoundContainer* newSound) { m_CrashSound = newSound; }
std::shared_ptr<SoundContainer> GetCrashSound() const { return m_CrashSound; }

/// Sets this ACraft's crash sound to a copy of the input.
/// @param newSound The new SoundContainer for this ACraft's crash sound to copy.
void SetCrashSound(const SoundContainer* newSound) {
if (!newSound)
m_CrashSound = nullptr;
else
m_CrashSound = std::make_shared<SoundContainer>(*newSound);
}

/// Protected member variable and method declarations
protected:
Expand All @@ -340,9 +356,9 @@ namespace RTE {
// The time it takes to open or close the hatch, in ms.
int m_HatchDelay;
// Sound for opening the hatch
SoundContainer* m_HatchOpenSound;
std::shared_ptr<SoundContainer> m_HatchOpenSound;
// Sound for closing the hatch
SoundContainer* m_HatchCloseSound;
std::shared_ptr<SoundContainer> m_HatchCloseSound;
std::deque<MovableObject*> m_CollectedInventory; //!< A separate inventory to temporarily store newly collected items, so that they don't get immediately ejected from the main inventory while the hatch is still open.
// All the possible exits for when ejecting stuff out of this.
std::list<Exit> m_Exits;
Expand All @@ -363,7 +379,7 @@ namespace RTE {
// Timer to measure how long ago a crash sound was played
Timer m_CrashTimer;
// Crash sound
SoundContainer* m_CrashSound;
std::shared_ptr<SoundContainer> m_CrashSound;
// Whether this can enter orbit and refund the owning team. If false, will use default out-of-bounds deletion behavior.
bool m_CanEnterOrbit;
// The maximum number of actors that fit in the inventory
Expand Down
56 changes: 28 additions & 28 deletions Source/Entities/ADoor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,23 @@ int ADoor::Create(const ADoor& reference) {
m_DoorMaterialID = reference.m_DoorMaterialID;

if (reference.m_DoorMoveStartSound) {
m_DoorMoveStartSound.reset(dynamic_cast<SoundContainer*>(reference.m_DoorMoveStartSound->Clone()));
m_DoorMoveStartSound = std::make_shared<SoundContainer>();
reference.m_DoorMoveStartSound->Clone(&*m_DoorMoveStartSound);
}

if (reference.m_DoorMoveSound) {
m_DoorMoveSound.reset(dynamic_cast<SoundContainer*>(reference.m_DoorMoveSound->Clone()));
m_DoorMoveSound = std::make_shared<SoundContainer>();
reference.m_DoorMoveSound->Clone(&*m_DoorMoveSound);
}

if (reference.m_DoorDirectionChangeSound) {
m_DoorDirectionChangeSound.reset(dynamic_cast<SoundContainer*>(reference.m_DoorDirectionChangeSound->Clone()));
m_DoorDirectionChangeSound = std::make_shared<SoundContainer>();
reference.m_DoorDirectionChangeSound->Clone(&*m_DoorDirectionChangeSound);
}

if (reference.m_DoorMoveEndSound) {
m_DoorMoveEndSound.reset(dynamic_cast<SoundContainer*>(reference.m_DoorMoveEndSound->Clone()));
m_DoorMoveEndSound = std::make_shared<SoundContainer>();
reference.m_DoorMoveEndSound->Clone(&*m_DoorMoveEndSound);
}

return 0;
Expand Down Expand Up @@ -152,10 +156,22 @@ int ADoor::ReadProperty(const std::string_view& propName, Reader& reader) {
});
MatchProperty("DrawMaterialLayerWhenOpen", { reader >> m_DrawMaterialLayerWhenOpen; });
MatchProperty("DrawMaterialLayerWhenClosed", { reader >> m_DrawMaterialLayerWhenClosed; });
MatchProperty("DoorMoveStartSound", { m_DoorMoveStartSound.reset(dynamic_cast<SoundContainer*>(g_PresetMan.ReadReflectedPreset(reader))); });
MatchProperty("DoorMoveSound", { m_DoorMoveSound.reset(dynamic_cast<SoundContainer*>(g_PresetMan.ReadReflectedPreset(reader))); });
MatchProperty("DoorDirectionChangeSound", { m_DoorDirectionChangeSound.reset(dynamic_cast<SoundContainer*>(g_PresetMan.ReadReflectedPreset(reader))); });
MatchProperty("DoorMoveEndSound", { m_DoorMoveEndSound.reset(dynamic_cast<SoundContainer*>(g_PresetMan.ReadReflectedPreset(reader))); });
MatchProperty("DoorMoveStartSound", {
m_DoorMoveStartSound = std::make_shared<SoundContainer>();
reader >> *m_DoorMoveStartSound;
});
MatchProperty("DoorMoveSound", {
m_DoorMoveSound = std::make_shared<SoundContainer>();
reader >> *m_DoorMoveSound;
});
MatchProperty("DoorDirectionChangeSound", {
m_DoorDirectionChangeSound = std::make_shared<SoundContainer>();
reader >> *m_DoorDirectionChangeSound;
});
MatchProperty("DoorMoveEndSound", {
m_DoorMoveEndSound = std::make_shared<SoundContainer>();
reader >> *m_DoorMoveEndSound;
});

EndPropertyList;
}
Expand Down Expand Up @@ -190,13 +206,13 @@ int ADoor::Save(Writer& writer) const {
writer.NewProperty("DrawMaterialLayerWhenClosed");
writer << m_DrawMaterialLayerWhenClosed;
writer.NewProperty("DoorMoveStartSound");
writer << m_DoorMoveStartSound.get();
writer << *m_DoorMoveStartSound;
writer.NewProperty("DoorMoveSound");
writer << m_DoorMoveSound.get();
writer << *m_DoorMoveSound;
writer.NewProperty("DoorDirectionChangeSound");
writer << m_DoorDirectionChangeSound.get();
writer << *m_DoorDirectionChangeSound;
writer.NewProperty("DoorMoveEndSound");
writer << m_DoorMoveEndSound.get();
writer << *m_DoorMoveEndSound;

return 0;
}
Expand Down Expand Up @@ -298,22 +314,6 @@ bool ADoor::EraseDoorMaterial(bool updateMaterialArea) {
return false;
}

void ADoor::SetDoorMoveStartSound(SoundContainer* newSound) {
m_DoorMoveStartSound.reset(newSound);
}

void ADoor::SetDoorMoveSound(SoundContainer* newSound) {
m_DoorMoveSound.reset(newSound);
}

void ADoor::SetDoorDirectionChangeSound(SoundContainer* newSound) {
m_DoorDirectionChangeSound.reset(newSound);
}

void ADoor::SetDoorMoveEndSound(SoundContainer* newSound) {
m_DoorMoveEndSound.reset(newSound);
}

void ADoor::TempEraseOrRedrawDoorMaterial(bool erase) {
if (!g_SceneMan.GetTerrain() || !g_SceneMan.GetTerrain()->GetMaterialBitmap()) {
return;
Expand Down
Loading
Loading