Skip to content

Commit 5742226

Browse files
committed
[BROKEN] make SoundContainer use shared_ptr everywhere
i tried but luabind 0.7.1 will not eat `std::shared_ptr` and i can't use `boost::shared_ptr` because the included boost headers literally do not have it for some reason so i'm just leaving this here as an archive of my work that might one day become workable if luabind is ever updated in this project
1 parent d0afdd6 commit 5742226

41 files changed

Lines changed: 875 additions & 611 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Source/Entities/ACrab.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ int ACrab::Create(const ACrab& reference) {
202202
m_BackupRBGFootGroup->SetLimbPos(atomGroupToUseAsFootGroupLFG->GetLimbPos());
203203

204204
if (reference.m_StrideSound) {
205-
m_StrideSound = dynamic_cast<SoundContainer*>(reference.m_StrideSound->Clone());
205+
m_StrideSound = std::make_shared<SoundContainer>();
206+
reference.m_StrideSound->Clone(&*m_StrideSound);
206207
}
207208

208209
m_MovementState = reference.m_MovementState;
@@ -297,8 +298,8 @@ int ACrab::ReadProperty(const std::string_view& propName, Reader& reader) {
297298
m_BackupRBGFootGroup->RemoveAllAtoms();
298299
});
299300
MatchProperty("StrideSound", {
300-
m_StrideSound = new SoundContainer;
301-
reader >> m_StrideSound;
301+
m_StrideSound = std::make_shared<SoundContainer>();
302+
reader >> *m_StrideSound;
302303
});
303304
MatchForwards("LStandLimbPath") MatchProperty("LeftStandLimbPath", { reader >> m_Paths[LEFTSIDE][FGROUND][STAND]; });
304305
MatchForwards("LWalkLimbPath") MatchProperty("LeftWalkLimbPath", { reader >> m_Paths[LEFTSIDE][FGROUND][WALK]; });
@@ -337,7 +338,7 @@ int ACrab::Save(Writer& writer) const {
337338
writer.NewProperty("RBGFootGroup");
338339
writer << m_pRBGFootGroup;
339340
writer.NewProperty("StrideSound");
340-
writer << m_StrideSound;
341+
writer << *m_StrideSound;
341342

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

371-
delete m_StrideSound;
372372
// for (deque<LimbPath *>::iterator itr = m_WalkPaths.begin();
373373
// itr != m_WalkPaths.end(); ++itr)
374374
// delete *itr;

Source/Entities/ACrab.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "Actor.h"
99
#include "LimbPath.h"
1010
#include "Leg.h"
11+
#include <memory>
1112

1213
struct BITMAP;
1314

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

246-
/// Gets this ACrab's stride sound. Ownership is NOT transferred!
247+
/// Gets this ACrab's stride sound.
247248
/// @return The SoundContainer for this ACrab's stride sound.
248-
SoundContainer* GetStrideSound() const { return m_StrideSound; }
249-
250-
/// Sets this ACrab's stride sound. Ownership IS transferred!
251-
/// @param newSound The new SoundContainer for this ACrab's stride sound.
252-
void SetStrideSound(SoundContainer* newSound) { m_StrideSound = newSound; }
249+
std::shared_ptr<SoundContainer> GetStrideSound() const { return m_StrideSound; }
250+
251+
/// Sets this ACrab's stride sound to a copy of the input.
252+
/// @param newSound The new SoundContainer for this ACrab's stride sound to copy.
253+
void SetStrideSound(const SoundContainer* newSound) {
254+
if (!newSound)
255+
m_StrideSound = nullptr;
256+
else
257+
m_StrideSound = std::make_shared<SoundContainer>(*newSound);
258+
}
253259

254260
/// Gets the upper limit of this ACrab's aim range.
255261
/// @return The upper limit of this ACrab's aim range.
@@ -301,7 +307,7 @@ namespace RTE {
301307
AtomGroup* m_pRBGFootGroup;
302308
AtomGroup* m_BackupRBGFootGroup;
303309
// The sound of the actor taking a step (think robot servo)
304-
SoundContainer* m_StrideSound;
310+
std::shared_ptr<SoundContainer> m_StrideSound;
305311
// Jetpack booster.
306312
AEJetpack* m_pJetpack;
307313
// Blink timer

Source/Entities/ACraft.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,15 @@ int ACraft::Create(const ACraft& reference) {
230230
m_HatchState = reference.m_HatchState;
231231
m_HatchDelay = reference.m_HatchDelay;
232232
if (reference.m_HatchOpenSound) {
233-
m_HatchOpenSound = dynamic_cast<SoundContainer*>(reference.m_HatchOpenSound->Clone());
233+
m_HatchOpenSound = std::make_shared<SoundContainer>();
234+
reference.m_HatchOpenSound->Clone(&*m_HatchOpenSound);
234235
}
235236
if (reference.m_HatchCloseSound) {
236-
m_HatchCloseSound = dynamic_cast<SoundContainer*>(reference.m_HatchCloseSound->Clone());
237+
m_HatchCloseSound = std::make_shared<SoundContainer>();
238+
reference.m_HatchCloseSound->Clone(&*m_HatchCloseSound);
237239
} else if (reference.m_HatchOpenSound) {
238-
m_HatchCloseSound = dynamic_cast<SoundContainer*>(reference.m_HatchOpenSound->Clone());
240+
m_HatchCloseSound = std::make_shared<SoundContainer>();
241+
reference.m_HatchOpenSound->Clone(&*m_HatchCloseSound);
239242
}
240243
for (std::deque<MovableObject*>::const_iterator niItr = reference.m_CollectedInventory.begin(); niItr != reference.m_CollectedInventory.end(); ++niItr)
241244
m_CollectedInventory.push_back(dynamic_cast<MovableObject*>((*niItr)->Clone()));
@@ -246,7 +249,8 @@ int ACraft::Create(const ACraft& reference) {
246249
m_HasDelivered = reference.m_HasDelivered;
247250
m_LandingCraft = reference.m_LandingCraft;
248251
if (reference.m_CrashSound) {
249-
m_CrashSound = dynamic_cast<SoundContainer*>(reference.m_CrashSound->Clone());
252+
m_CrashSound = std::make_shared<SoundContainer>();
253+
reference.m_CrashSound->Clone(&*m_CrashSound);
250254
}
251255

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

268272
MatchProperty("HatchDelay", { reader >> m_HatchDelay; });
269273
MatchProperty("HatchOpenSound", {
270-
m_HatchOpenSound = new SoundContainer;
271-
reader >> m_HatchOpenSound;
274+
m_HatchOpenSound = std::make_shared<SoundContainer>();
275+
reader >> *m_HatchOpenSound;
272276
});
273277
MatchProperty("HatchCloseSound", {
274-
m_HatchCloseSound = new SoundContainer;
275-
reader >> m_HatchCloseSound;
278+
m_HatchCloseSound = std::make_shared<SoundContainer>();
279+
reader >> *m_HatchCloseSound;
276280
});
277281
MatchProperty("CrashSound", {
278-
m_CrashSound = new SoundContainer;
279-
reader >> m_CrashSound;
282+
m_CrashSound = std::make_shared<SoundContainer>();
283+
reader >> *m_CrashSound;
280284
});
281285
MatchProperty("AddExit",
282286
{
@@ -301,9 +305,9 @@ int ACraft::Save(Writer& writer) const {
301305
writer.NewProperty("HatchDelay");
302306
writer << m_HatchDelay;
303307
writer.NewProperty("HatchOpenSound");
304-
writer << m_HatchOpenSound;
308+
writer << *m_HatchOpenSound;
305309
writer.NewProperty("HatchCloseSound");
306-
writer << m_HatchCloseSound;
310+
writer << *m_HatchCloseSound;
307311
for (std::list<Exit>::const_iterator itr = m_Exits.begin(); itr != m_Exits.end(); ++itr) {
308312
writer.NewProperty("AddExit");
309313
writer << (*itr);
@@ -316,7 +320,7 @@ int ACraft::Save(Writer& writer) const {
316320
writer << m_LandingCraft;
317321

318322
writer.NewProperty("CrashSound");
319-
writer << m_CrashSound;
323+
writer << *m_CrashSound;
320324

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

334338
void ACraft::Destroy(bool notInherited) {
335-
delete m_HatchOpenSound;
336-
delete m_HatchCloseSound;
337-
delete m_CrashSound;
338-
339339
if (!notInherited)
340340
Actor::Destroy();
341341
Clear();

Source/Entities/ACraft.h

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/// Inclusions of header files
88
#include "Actor.h"
99
#include "LimbPath.h"
10+
#include <memory>
1011

1112
struct BITMAP;
1213

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

308-
/// Gets this ACraft's hatch opening sound. Ownership is NOT transferred!
309+
/// Gets this ACraft's hatch opening sound.
309310
/// @return The SoundContainer for this ACraft's hatch opening sound.
310-
SoundContainer* GetHatchOpenSound() const { return m_HatchOpenSound; }
311-
312-
/// Sets this ACraft's hatch opening sound. Ownership IS transferred!
313-
/// @param newSound The new SoundContainer for this ACraft's hatch opening sound.
314-
void SetHatchOpenSound(SoundContainer* newSound) { m_HatchOpenSound = newSound; }
311+
std::shared_ptr<SoundContainer> GetHatchOpenSound() const { return m_HatchOpenSound; }
312+
313+
/// Sets this ACraft's hatch opening sound to a copy of the input.
314+
/// @param newSound The new SoundContainer for this ACraft's hatch opening sound to copy.
315+
void SetHatchOpenSound(const SoundContainer* newSound) {
316+
if (!newSound)
317+
m_HatchOpenSound = nullptr;
318+
else
319+
m_HatchOpenSound = std::make_shared<SoundContainer>(*newSound);
320+
}
315321

316-
/// Gets this ACraft's hatch closing sound. Ownership is NOT transferred!
322+
/// Gets this ACraft's hatch closing sound.
317323
/// @return The SoundContainer for this ACraft's hatch closing sound.
318-
SoundContainer* GetHatchCloseSound() const { return m_HatchCloseSound; }
319-
320-
/// Sets this ACraft's hatch closing sound. Ownership IS transferred!
321-
/// @param newSound The new SoundContainer for this ACraft's hatch closing sound.
322-
void SetHatchCloseSound(SoundContainer* newSound) { m_HatchCloseSound = newSound; }
324+
std::shared_ptr<SoundContainer> GetHatchCloseSound() const { return m_HatchCloseSound; }
325+
326+
/// Sets this ACraft's hatch closing sound to a copy of the input.
327+
/// @param newSound The new SoundContainer for this ACraft's hatch closing sound to copy.
328+
void SetHatchCloseSound(const SoundContainer* newSound) {
329+
if (!newSound)
330+
m_HatchCloseSound = nullptr;
331+
else
332+
m_HatchCloseSound = std::make_shared<SoundContainer>(*newSound);
333+
}
323334

324-
/// Gets this ACraft's crash sound. Ownership is NOT transferred!
335+
/// Gets this ACraft's crash sound.
325336
/// @return The SoundContainer for this ACraft's crash sound.
326-
SoundContainer* GetCrashSound() const { return m_CrashSound; }
327-
328-
/// Sets this ACraft's crash sound. Ownership IS transferred!
329-
/// @param newSound The new SoundContainer for this ACraft's crash sound.
330-
void SetCrashSound(SoundContainer* newSound) { m_CrashSound = newSound; }
337+
std::shared_ptr<SoundContainer> GetCrashSound() const { return m_CrashSound; }
338+
339+
/// Sets this ACraft's crash sound to a copy of the input.
340+
/// @param newSound The new SoundContainer for this ACraft's crash sound to copy.
341+
void SetCrashSound(const SoundContainer* newSound) {
342+
if (!newSound)
343+
m_CrashSound = nullptr;
344+
else
345+
m_CrashSound = std::make_shared<SoundContainer>(*newSound);
346+
}
331347

332348
/// Protected member variable and method declarations
333349
protected:
@@ -340,9 +356,9 @@ namespace RTE {
340356
// The time it takes to open or close the hatch, in ms.
341357
int m_HatchDelay;
342358
// Sound for opening the hatch
343-
SoundContainer* m_HatchOpenSound;
359+
std::shared_ptr<SoundContainer> m_HatchOpenSound;
344360
// Sound for closing the hatch
345-
SoundContainer* m_HatchCloseSound;
361+
std::shared_ptr<SoundContainer> m_HatchCloseSound;
346362
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.
347363
// All the possible exits for when ejecting stuff out of this.
348364
std::list<Exit> m_Exits;
@@ -363,7 +379,7 @@ namespace RTE {
363379
// Timer to measure how long ago a crash sound was played
364380
Timer m_CrashTimer;
365381
// Crash sound
366-
SoundContainer* m_CrashSound;
382+
std::shared_ptr<SoundContainer> m_CrashSound;
367383
// Whether this can enter orbit and refund the owning team. If false, will use default out-of-bounds deletion behavior.
368384
bool m_CanEnterOrbit;
369385
// The maximum number of actors that fit in the inventory

Source/Entities/ADoor.cpp

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,23 @@ int ADoor::Create(const ADoor& reference) {
9191
m_DoorMaterialID = reference.m_DoorMaterialID;
9292

9393
if (reference.m_DoorMoveStartSound) {
94-
m_DoorMoveStartSound.reset(dynamic_cast<SoundContainer*>(reference.m_DoorMoveStartSound->Clone()));
94+
m_DoorMoveStartSound = std::make_shared<SoundContainer>();
95+
reference.m_DoorMoveStartSound->Clone(&*m_DoorMoveStartSound);
9596
}
9697

9798
if (reference.m_DoorMoveSound) {
98-
m_DoorMoveSound.reset(dynamic_cast<SoundContainer*>(reference.m_DoorMoveSound->Clone()));
99+
m_DoorMoveSound = std::make_shared<SoundContainer>();
100+
reference.m_DoorMoveSound->Clone(&*m_DoorMoveSound);
99101
}
100102

101103
if (reference.m_DoorDirectionChangeSound) {
102-
m_DoorDirectionChangeSound.reset(dynamic_cast<SoundContainer*>(reference.m_DoorDirectionChangeSound->Clone()));
104+
m_DoorDirectionChangeSound = std::make_shared<SoundContainer>();
105+
reference.m_DoorDirectionChangeSound->Clone(&*m_DoorDirectionChangeSound);
103106
}
104107

105108
if (reference.m_DoorMoveEndSound) {
106-
m_DoorMoveEndSound.reset(dynamic_cast<SoundContainer*>(reference.m_DoorMoveEndSound->Clone()));
109+
m_DoorMoveEndSound = std::make_shared<SoundContainer>();
110+
reference.m_DoorMoveEndSound->Clone(&*m_DoorMoveEndSound);
107111
}
108112

109113
return 0;
@@ -152,10 +156,22 @@ int ADoor::ReadProperty(const std::string_view& propName, Reader& reader) {
152156
});
153157
MatchProperty("DrawMaterialLayerWhenOpen", { reader >> m_DrawMaterialLayerWhenOpen; });
154158
MatchProperty("DrawMaterialLayerWhenClosed", { reader >> m_DrawMaterialLayerWhenClosed; });
155-
MatchProperty("DoorMoveStartSound", { m_DoorMoveStartSound.reset(dynamic_cast<SoundContainer*>(g_PresetMan.ReadReflectedPreset(reader))); });
156-
MatchProperty("DoorMoveSound", { m_DoorMoveSound.reset(dynamic_cast<SoundContainer*>(g_PresetMan.ReadReflectedPreset(reader))); });
157-
MatchProperty("DoorDirectionChangeSound", { m_DoorDirectionChangeSound.reset(dynamic_cast<SoundContainer*>(g_PresetMan.ReadReflectedPreset(reader))); });
158-
MatchProperty("DoorMoveEndSound", { m_DoorMoveEndSound.reset(dynamic_cast<SoundContainer*>(g_PresetMan.ReadReflectedPreset(reader))); });
159+
MatchProperty("DoorMoveStartSound", {
160+
m_DoorMoveStartSound = std::make_shared<SoundContainer>();
161+
reader >> *m_DoorMoveStartSound;
162+
});
163+
MatchProperty("DoorMoveSound", {
164+
m_DoorMoveSound = std::make_shared<SoundContainer>();
165+
reader >> *m_DoorMoveSound;
166+
});
167+
MatchProperty("DoorDirectionChangeSound", {
168+
m_DoorDirectionChangeSound = std::make_shared<SoundContainer>();
169+
reader >> *m_DoorDirectionChangeSound;
170+
});
171+
MatchProperty("DoorMoveEndSound", {
172+
m_DoorMoveEndSound = std::make_shared<SoundContainer>();
173+
reader >> *m_DoorMoveEndSound;
174+
});
159175

160176
EndPropertyList;
161177
}
@@ -190,13 +206,13 @@ int ADoor::Save(Writer& writer) const {
190206
writer.NewProperty("DrawMaterialLayerWhenClosed");
191207
writer << m_DrawMaterialLayerWhenClosed;
192208
writer.NewProperty("DoorMoveStartSound");
193-
writer << m_DoorMoveStartSound.get();
209+
writer << *m_DoorMoveStartSound;
194210
writer.NewProperty("DoorMoveSound");
195-
writer << m_DoorMoveSound.get();
211+
writer << *m_DoorMoveSound;
196212
writer.NewProperty("DoorDirectionChangeSound");
197-
writer << m_DoorDirectionChangeSound.get();
213+
writer << *m_DoorDirectionChangeSound;
198214
writer.NewProperty("DoorMoveEndSound");
199-
writer << m_DoorMoveEndSound.get();
215+
writer << *m_DoorMoveEndSound;
200216

201217
return 0;
202218
}
@@ -298,22 +314,6 @@ bool ADoor::EraseDoorMaterial(bool updateMaterialArea) {
298314
return false;
299315
}
300316

301-
void ADoor::SetDoorMoveStartSound(SoundContainer* newSound) {
302-
m_DoorMoveStartSound.reset(newSound);
303-
}
304-
305-
void ADoor::SetDoorMoveSound(SoundContainer* newSound) {
306-
m_DoorMoveSound.reset(newSound);
307-
}
308-
309-
void ADoor::SetDoorDirectionChangeSound(SoundContainer* newSound) {
310-
m_DoorDirectionChangeSound.reset(newSound);
311-
}
312-
313-
void ADoor::SetDoorMoveEndSound(SoundContainer* newSound) {
314-
m_DoorMoveEndSound.reset(newSound);
315-
}
316-
317317
void ADoor::TempEraseOrRedrawDoorMaterial(bool erase) {
318318
if (!g_SceneMan.GetTerrain() || !g_SceneMan.GetTerrain()->GetMaterialBitmap()) {
319319
return;

0 commit comments

Comments
 (0)