Skip to content

Commit 9d00ae7

Browse files
committed
Make all entity bindings returning iterators have affect outside of lua by changing referenced std iterators to work over pointers instead of raw values, meaning the value copies passed to lua are value copies of pointers, not raw values.
1 parent 3e6f48d commit 9d00ae7

File tree

11 files changed

+142
-128
lines changed

11 files changed

+142
-128
lines changed

Source/Activities/AreaEditor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,12 @@ void AreaEditor::Update() {
294294
m_pEditorGUI->SetEditorGUIMode(AreaEditorGUI::PREADDMOVEBOX);
295295
} else {
296296
// Make and name new Area
297-
Scene::Area newArea(m_pNewAreaName->GetText());
297+
Scene::Area* newArea = new Scene::Area(m_pNewAreaName->GetText());
298298
pCurrentScene->m_AreaList.push_back(newArea);
299299
// Set the new area as the active one in the GUI, note we're getting the correct one from the scene, it's a copy of the one passed in
300-
m_pEditorGUI->SetCurrentArea(pCurrentScene->GetArea(newArea.GetName()));
300+
m_pEditorGUI->SetCurrentArea(pCurrentScene->GetArea(newArea->GetName()));
301301
// Update teh picker list of the GUI so we can mousewheel between all the Areas, incl the new one
302-
m_pEditorGUI->UpdatePickerList(newArea.GetName());
302+
m_pEditorGUI->UpdatePickerList(newArea->GetName());
303303
}
304304

305305
// Change mode to start editing the new/newly selected Area

Source/Activities/GibEditor.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -400,14 +400,14 @@ void GibEditor::Update() {
400400
m_pEditedObject->Update();
401401

402402
// Make proxy copies of the loaded objects' gib reference instances and place them in the list to be edited
403-
std::list<Gib>* pLoadedGibList = m_pEditedObject->GetGibList();
403+
std::list<Gib*>* pLoadedGibList = m_pEditedObject->GetGibList();
404404
std::list<MovableObject*>* pEditedGibList = m_pEditorGUI->GetPlacedGibs();
405405
MovableObject* pGibCopy = 0;
406406

407407
for (auto gItr = pLoadedGibList->begin(); gItr != pLoadedGibList->end(); ++gItr) {
408-
pGibCopy = dynamic_cast<MovableObject*>((*gItr).GetParticlePreset()->Clone());
408+
pGibCopy = dynamic_cast<MovableObject*>((*gItr)->GetParticlePreset()->Clone());
409409
if (pGibCopy) {
410-
pGibCopy->SetPos(m_pEditedObject->GetPos() + (*gItr).GetOffset());
410+
pGibCopy->SetPos(m_pEditedObject->GetPos() + (*gItr)->GetOffset());
411411
pEditedGibList->push_back(pGibCopy);
412412
}
413413
pGibCopy = 0;
@@ -599,8 +599,8 @@ bool GibEditor::SaveObject(const std::string& saveAsName, bool forceOverwrite) {
599599
}
600600
objectWriter.NewProperty(addObjectType);
601601
m_pEditedObject->Entity::Save(objectWriter);
602-
for (const Gib& gib: *m_pEditedObject->GetGibList()) {
603-
objectWriter.NewPropertyWithValue("AddGib", gib);
602+
for (const Gib* gib: *m_pEditedObject->GetGibList()) {
603+
objectWriter.NewPropertyWithValue("AddGib", *gib);
604604
}
605605
objectWriter.ObjectEnd();
606606
objectWriter.EndWrite();
@@ -626,18 +626,18 @@ void GibEditor::StuffEditedGibs(MOSRotating* pEditedObject) {
626626
return;
627627

628628
// Replace the gibs of the object with the proxies that have been edited in the gui
629-
std::list<Gib>* pObjectGibList = pEditedObject->GetGibList();
629+
std::list<Gib*>* pObjectGibList = pEditedObject->GetGibList();
630630
pObjectGibList->clear();
631631

632632
// Take each proxy object and stuff it into a Gib instance which then gets stuffed into the object to be saved
633633
std::list<MovableObject*>* pProxyGibList = m_pEditorGUI->GetPlacedGibs();
634634
for (std::list<MovableObject*>::iterator gItr = pProxyGibList->begin(); gItr != pProxyGibList->end(); ++gItr) {
635-
Gib newGib;
635+
Gib* newGib;
636636
// Only set the refernce instance directly from the isntanceman. OWNERSHIP IS NOT TRANSFERRED!
637-
newGib.m_GibParticle = dynamic_cast<const MovableObject*>(g_PresetMan.GetEntityPreset((*gItr)->GetClassName(), (*gItr)->GetPresetName(), m_ModuleSpaceID));
638-
if (newGib.m_GibParticle) {
639-
newGib.m_Count = 1;
640-
newGib.m_Offset = (*gItr)->GetPos() - pEditedObject->GetPos();
637+
newGib->m_GibParticle = dynamic_cast<const MovableObject*>(g_PresetMan.GetEntityPreset((*gItr)->GetClassName(), (*gItr)->GetPresetName(), m_ModuleSpaceID));
638+
if (newGib->m_GibParticle) {
639+
newGib->m_Count = 1;
640+
newGib->m_Offset = (*gItr)->GetPos() - pEditedObject->GetPos();
641641
// TODO: do proper velocity calculations here!
642642
// ... actually leave these as 0 and let them be calculated in GibThis
643643
// newGib.m_MinVelocity = (100.0f + 50.0f * NormalRand()) / (*gItr)->GetMass();

Source/Entities/MOSRotating.cpp

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ int MOSRotating::Create(const MOSRotating& reference) {
228228
}
229229
m_ReferenceHardcodedAttachableUniqueIDs.clear();
230230

231-
for (const Gib& gib: reference.m_Gibs) {
232-
m_Gibs.push_back(gib);
231+
for (const Gib* gib: reference.m_Gibs) {
232+
m_Gibs.push_back(new Gib(*gib));
233233
}
234234

235235
m_GibImpulseLimit = reference.m_GibImpulseLimit;
@@ -302,8 +302,8 @@ int MOSRotating::ReadProperty(const std::string_view& propName, Reader& reader)
302302
});
303303
MatchProperty("AddGib",
304304
{
305-
Gib gib;
306-
reader >> gib;
305+
Gib* gib = new Gib();
306+
reader >> *gib;
307307
m_Gibs.push_back(gib);
308308
});
309309
MatchProperty("GibImpulseLimit", { reader >> m_GibImpulseLimit; });
@@ -356,7 +356,7 @@ int MOSRotating::Save(Writer& writer) const {
356356
*/
357357
for (auto gItr = m_Gibs.begin(); gItr != m_Gibs.end(); ++gItr) {
358358
writer.NewProperty("AddGib");
359-
writer << (*gItr);
359+
writer << (**gItr);
360360
}
361361
/*
362362
writer.NewProperty("GibImpulseLimit");
@@ -555,6 +555,10 @@ void MOSRotating::Destroy(bool notInherited) {
555555
delete (*itr);
556556
}
557557

558+
for (auto gib = m_Gibs.begin(); gib != m_Gibs.end(); ++gib) {
559+
delete (*gib);
560+
}
561+
558562
for (auto aItr = m_Attachables.begin(); aItr != m_Attachables.end(); ++aItr) {
559563
if (m_HardcodedAttachableUniqueIDsAndRemovers.find((*aItr)->GetUniqueID()) == m_HardcodedAttachableUniqueIDsAndRemovers.end()) {
560564
delete (*aItr);
@@ -895,17 +899,17 @@ void MOSRotating::CreateGibsWhenGibbing(const Vector& impactImpulse, MovableObje
895899
g_CameraMan.AddScreenShake(m_GibScreenShakeAmount, m_Pos);
896900
}
897901

898-
for (const Gib& gibSettingsObject: m_Gibs) {
899-
if (gibSettingsObject.GetCount() == 0) {
902+
for (const Gib* gibSettingsObject: m_Gibs) {
903+
if (gibSettingsObject->GetCount() == 0) {
900904
continue;
901905
}
902-
MovableObject* gibParticleClone = dynamic_cast<MovableObject*>(gibSettingsObject.GetParticlePreset()->Clone());
906+
MovableObject* gibParticleClone = dynamic_cast<MovableObject*>(gibSettingsObject->GetParticlePreset()->Clone());
903907

904-
int count = gibSettingsObject.GetCount();
905-
float lifeVariation = gibSettingsObject.GetLifeVariation();
906-
float spread = gibSettingsObject.GetSpread();
907-
float minVelocity = gibSettingsObject.GetMinVelocity();
908-
float maxVelocity = gibSettingsObject.GetMaxVelocity();
908+
int count = gibSettingsObject->GetCount();
909+
float lifeVariation = gibSettingsObject->GetLifeVariation();
910+
float spread = gibSettingsObject->GetSpread();
911+
float minVelocity = gibSettingsObject->GetMinVelocity();
912+
float maxVelocity = gibSettingsObject->GetMaxVelocity();
909913

910914
float mass = (gibParticleClone->GetMass() != 0 ? gibParticleClone->GetMass() : 0.0001F);
911915
int lifetime = gibParticleClone->GetLifetime();
@@ -923,18 +927,18 @@ void MOSRotating::CreateGibsWhenGibbing(const Vector& impactImpulse, MovableObje
923927
}
924928

925929
float velocityRange = maxVelocity - minVelocity;
926-
Vector rotatedGibOffset = RotateOffset(gibSettingsObject.GetOffset());
930+
Vector rotatedGibOffset = RotateOffset(gibSettingsObject->GetOffset());
927931

928932
// The "Spiral" spread mode uses the fermat spiral as means to determine the velocity of the gib particles, resulting in a evenly spaced out circle (or ring) of particles.
929-
if (gibSettingsObject.GetSpreadMode() == Gib::SpreadMode::SpreadSpiral) {
933+
if (gibSettingsObject->GetSpreadMode() == Gib::SpreadMode::SpreadSpiral) {
930934
float maxRadius = std::sqrt(static_cast<float>(count));
931935
float scale = velocityRange / maxRadius;
932936
float randAngle = c_PI * RandomNormalNum();
933937
float goldenAngle = 2.39996F;
934938

935939
for (int i = 0; i < count; i++) {
936940
if (i > 0) {
937-
gibParticleClone = dynamic_cast<MovableObject*>(gibSettingsObject.GetParticlePreset()->Clone());
941+
gibParticleClone = dynamic_cast<MovableObject*>(gibSettingsObject->GetParticlePreset()->Clone());
938942
}
939943

940944
float radius = std::sqrt(static_cast<float>(count - i));
@@ -944,20 +948,20 @@ void MOSRotating::CreateGibsWhenGibbing(const Vector& impactImpulse, MovableObje
944948
gibVelocity.RadRotate(randAngle + RandomNum(0.0F, spread) + static_cast<float>(i) * goldenAngle);
945949

946950
Vector offsetFromRootParent = m_Pos - GetRootParent()->GetPos() + rotatedGibOffset;
947-
Vector rotationalVelocity = (offsetFromRootParent.GetPerpendicular() * GetRootParent()->GetAngularVel() * gibSettingsObject.InheritsVelocity()) / c_PPM;
951+
Vector rotationalVelocity = (offsetFromRootParent.GetPerpendicular() * GetRootParent()->GetAngularVel() * gibSettingsObject->InheritsVelocity()) / c_PPM;
948952
gibVelocity += rotationalVelocity;
949-
gibParticleClone->SetAngularVel(gibParticleClone->GetAngularVel() + GetRootParent()->GetAngularVel() * gibSettingsObject.InheritsAngularVelocity());
953+
gibParticleClone->SetAngularVel(gibParticleClone->GetAngularVel() + GetRootParent()->GetAngularVel() * gibSettingsObject->InheritsAngularVelocity());
950954

951955
if (lifetime != 0) {
952956
gibParticleClone->SetLifetime(std::max(static_cast<int>(static_cast<float>(lifetime) * (1.0F - lifeVariation * ((radius / maxRadius) * 0.75F + RandomNormalNum() * 0.25F))), 1));
953957
}
954958
gibParticleClone->SetRotAngle(gibVelocity.GetAbsRadAngle() + (m_HFlipped ? c_PI : 0));
955959
gibParticleClone->SetAngularVel((gibParticleClone->GetAngularVel() * 0.35F) + (gibParticleClone->GetAngularVel() * 0.65F / mass) * RandomNum());
956-
gibParticleClone->SetVel(gibVelocity + ((m_PrevVel + m_Vel) / 2) * gibSettingsObject.InheritsVelocity());
960+
gibParticleClone->SetVel(gibVelocity + ((m_PrevVel + m_Vel) / 2) * gibSettingsObject->InheritsVelocity());
957961
if (movableObjectToIgnore) {
958962
gibParticleClone->SetWhichMOToNotHit(movableObjectToIgnore);
959963
}
960-
if (gibSettingsObject.IgnoresTeamHits()) {
964+
if (gibSettingsObject->IgnoresTeamHits()) {
961965
gibParticleClone->SetTeam(m_Team);
962966
gibParticleClone->SetIgnoresTeamHits(true);
963967
}
@@ -967,7 +971,7 @@ void MOSRotating::CreateGibsWhenGibbing(const Vector& impactImpulse, MovableObje
967971
} else {
968972
for (int i = 0; i < count; i++) {
969973
if (i > 0) {
970-
gibParticleClone = dynamic_cast<MovableObject*>(gibSettingsObject.GetParticlePreset()->Clone());
974+
gibParticleClone = dynamic_cast<MovableObject*>(gibSettingsObject->GetParticlePreset()->Clone());
971975
}
972976

973977
if (gibParticleClone->GetLifetime() != 0) {
@@ -991,31 +995,31 @@ void MOSRotating::CreateGibsWhenGibbing(const Vector& impactImpulse, MovableObje
991995
// TODO: Figure out how much the magnitude of an offset should affect spread
992996
float gibSpread = (rotatedGibOffset.IsZero() && spread == 0.1F) ? c_PI : spread;
993997
// Determine the primary direction of the gib particles.
994-
if (gibSettingsObject.InheritsVelocity() > 0 && !impactImpulse.IsZero()) {
998+
if (gibSettingsObject->InheritsVelocity() > 0 && !impactImpulse.IsZero()) {
995999
gibVelocity.RadRotate(impactImpulse.GetAbsRadAngle());
9961000
} else if (!rotatedGibOffset.IsZero()) {
9971001
gibVelocity.RadRotate(rotatedGibOffset.GetAbsRadAngle());
9981002
} else {
9991003
gibVelocity.RadRotate(m_Rotation.GetRadAngle() + (m_HFlipped ? c_PI : 0));
10001004
}
10011005
// The "Even" spread will spread all gib particles evenly in an arc, while maintaining a randomized velocity magnitude.
1002-
if (gibSettingsObject.GetSpreadMode() == Gib::SpreadMode::SpreadEven) {
1006+
if (gibSettingsObject->GetSpreadMode() == Gib::SpreadMode::SpreadEven) {
10031007
gibVelocity.RadRotate(gibSpread - (gibSpread * 2.0F * static_cast<float>(i) / static_cast<float>(count)));
10041008
} else {
10051009
gibVelocity.RadRotate(gibSpread * RandomNormalNum());
10061010
}
10071011

10081012
Vector offsetFromRootParent = m_Pos - GetRootParent()->GetPos() + rotatedGibOffset;
1009-
Vector rotationalVelocity = (offsetFromRootParent.GetPerpendicular() * GetRootParent()->GetAngularVel() * gibSettingsObject.InheritsVelocity()) / c_PPM;
1013+
Vector rotationalVelocity = (offsetFromRootParent.GetPerpendicular() * GetRootParent()->GetAngularVel() * gibSettingsObject->InheritsVelocity()) / c_PPM;
10101014
gibVelocity += rotationalVelocity;
1011-
gibParticleClone->SetAngularVel(gibParticleClone->GetAngularVel() + GetRootParent()->GetAngularVel() * gibSettingsObject.InheritsAngularVelocity());
1015+
gibParticleClone->SetAngularVel(gibParticleClone->GetAngularVel() + GetRootParent()->GetAngularVel() * gibSettingsObject->InheritsAngularVelocity());
10121016

1013-
gibParticleClone->SetVel(gibVelocity + ((m_PrevVel + m_Vel) / 2) * gibSettingsObject.InheritsVelocity());
1017+
gibParticleClone->SetVel(gibVelocity + ((m_PrevVel + m_Vel) / 2) * gibSettingsObject->InheritsVelocity());
10141018

10151019
if (movableObjectToIgnore) {
10161020
gibParticleClone->SetWhichMOToNotHit(movableObjectToIgnore);
10171021
}
1018-
if (gibSettingsObject.IgnoresTeamHits()) {
1022+
if (gibSettingsObject->IgnoresTeamHits()) {
10191023
gibParticleClone->SetTeam(m_Team);
10201024
gibParticleClone->SetIgnoresTeamHits(true);
10211025
}

Source/Entities/MOSRotating.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ namespace RTE {
146146

147147
/// Gets direct access to the list of object this is to generate upon gibbing.
148148
/// @return A pointer to the list of gibs. Ownership is NOT transferred!
149-
std::list<Gib>* GetGibList() { return &m_Gibs; }
149+
std::list<Gib*>* GetGibList() { return &m_Gibs; }
150150

151151
/// Adds graphical recoil offset to this MOSprite according to its angle.
152152
void AddRecoil();
@@ -551,7 +551,7 @@ namespace RTE {
551551
float m_FarthestAttachableDistanceAndRadius; //!< The distance + radius of the radius affecting Attachable.
552552
float m_AttachableAndWoundMass; //!< The mass of all Attachables and wounds on this MOSRotating. Used in combination with its actual mass and any other affecting factors to get its total mass.
553553
// The list of Gib:s this will create when gibbed
554-
std::list<Gib> m_Gibs;
554+
std::list<Gib*> m_Gibs;
555555
// The amount of impulse force required to gib this, in kg * (m/s). 0 means no limit
556556
float m_GibImpulseLimit;
557557
int m_GibWoundLimit; //!< The number of wounds that will gib this MOSRotating. 0 means that it can't be gibbed via wounds.

Source/Entities/Scene.cpp

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,8 @@ int Scene::Create(const Scene& reference) {
431431
}
432432

433433
// Copy areas
434-
for (std::list<Area>::const_iterator aItr = reference.m_AreaList.begin(); aItr != reference.m_AreaList.end(); ++aItr)
435-
m_AreaList.push_back(*aItr);
434+
for (Area* area: reference.m_AreaList)
435+
m_AreaList.push_back(new Area(*area));
436436

437437
m_GlobalAcc = reference.m_GlobalAcc;
438438

@@ -1156,11 +1156,11 @@ int Scene::Save(Writer& writer) const {
11561156
writer.NewProperty("ScanScheduledTeam4");
11571157
writer << m_ScanScheduled[Activity::TeamFour];
11581158
}
1159-
for (std::list<Area>::const_iterator aItr = m_AreaList.begin(); aItr != m_AreaList.end(); ++aItr) {
1159+
for (Area* area: m_AreaList) {
11601160
// Only write the area if it has any boxes/area at all
1161-
if (doFullGameSave || !(*aItr).HasNoArea()) {
1161+
if (doFullGameSave || !(*area).HasNoArea()) {
11621162
writer.NewProperty("AddArea");
1163-
writer << *aItr;
1163+
writer << *area;
11641164
}
11651165
}
11661166
writer.NewProperty("GlobalAcceleration");
@@ -1443,6 +1443,9 @@ void Scene::Destroy(bool notInherited) {
14431443
*slItr = 0;
14441444
}
14451445

1446+
for (Area* area: m_AreaList)
1447+
delete area;
1448+
14461449
delete m_apUnseenLayer[Activity::TeamOne];
14471450
delete m_apUnseenLayer[Activity::TeamTwo];
14481451
delete m_apUnseenLayer[Activity::TeamThree];
@@ -1840,33 +1843,33 @@ int Scene::GetResidentBrainCount() const {
18401843
}
18411844

18421845
bool Scene::SetArea(Area& newArea) {
1843-
for (std::list<Area>::iterator aItr = m_AreaList.begin(); aItr != m_AreaList.end(); ++aItr) {
1846+
for (Area* area: m_AreaList) {
18441847
// Try to find an existing area of the same name
1845-
if ((*aItr).GetName() == newArea.GetName()) {
1848+
if (area->GetName() == newArea.GetName()) {
18461849
// Deep copy into the existing area
1847-
(*aItr).Reset();
1848-
(*aItr).Create(newArea);
1850+
area->Reset();
1851+
area->Create(newArea);
18491852
return true;
18501853
}
18511854
}
18521855
// Couldn't find one, so just add the new Area
1853-
m_AreaList.push_back(newArea);
1856+
m_AreaList.push_back(new Area(newArea));
18541857

18551858
return false;
18561859
}
18571860

18581861
bool Scene::HasArea(std::string areaName) {
1859-
for (std::list<Area>::iterator aItr = m_AreaList.begin(); aItr != m_AreaList.end(); ++aItr) {
1860-
if ((*aItr).GetName() == areaName)
1862+
for (Area* area: m_AreaList) {
1863+
if (area->GetName() == areaName)
18611864
return true;
18621865
}
18631866
return false;
18641867
}
18651868

18661869
Scene::Area* Scene::GetArea(const std::string_view& areaName, bool required) {
1867-
for (Scene::Area& area: m_AreaList) {
1868-
if (area.GetName() == areaName) {
1869-
return &area;
1870+
for (Scene::Area*& area: m_AreaList) {
1871+
if (area->GetName() == areaName) {
1872+
return area;
18701873
}
18711874
}
18721875

@@ -1878,8 +1881,8 @@ Scene::Area* Scene::GetArea(const std::string_view& areaName, bool required) {
18781881
}
18791882

18801883
bool Scene::RemoveArea(std::string areaName) {
1881-
for (std::list<Area>::iterator aItr = m_AreaList.begin(); aItr != m_AreaList.end(); ++aItr) {
1882-
if ((*aItr).GetName() == areaName) {
1884+
for (std::list<Area*>::iterator aItr = m_AreaList.begin(); aItr != m_AreaList.end(); ++aItr) {
1885+
if ((*aItr)->GetName() == areaName) {
18831886
m_AreaList.erase(aItr);
18841887
return true;
18851888
}
@@ -1891,8 +1894,8 @@ bool Scene::WithinArea(std::string areaName, const Vector& point) const {
18911894
if (areaName.empty())
18921895
return false;
18931896

1894-
for (std::list<Area>::const_iterator aItr = m_AreaList.begin(); aItr != m_AreaList.end(); ++aItr) {
1895-
if ((*aItr).GetName() == areaName && (*aItr).IsInside(point))
1897+
for (std::list<Area*>::const_iterator aItr = m_AreaList.begin(); aItr != m_AreaList.end(); ++aItr) {
1898+
if ((*aItr)->GetName() == areaName && (*aItr)->IsInside(point))
18961899
return true;
18971900
}
18981901

Source/Entities/Scene.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ namespace RTE {
345345

346346
/// Adds area to the list if this scene's areas.
347347
/// @param m_AreaList.push_back(newArea Area to add.
348-
void AddArea(Scene::Area& newArea) { m_AreaList.push_back(newArea); }
348+
void AddArea(Scene::Area& newArea) { m_AreaList.push_back(new Scene::Area(newArea)); }
349349

350350
/// Creates a new SceneLayer for a specific team and fills it with black
351351
/// pixels that end up being a specific size on the screen.
@@ -767,7 +767,7 @@ namespace RTE {
767767
bool m_ScanScheduled[Activity::MaxTeamCount];
768768

769769
// List of all the specified Area's of the scene
770-
std::list<Area> m_AreaList;
770+
std::list<Area*> m_AreaList;
771771

772772
// List of navigatable areas in the scene. If this list is empty, the entire scene is assumed to be navigatable
773773
std::vector<std::string> m_NavigatableAreas;

0 commit comments

Comments
 (0)