Skip to content

Commit 53d0a56

Browse files
committed
Merge branch 'development' into browncoat-mission
2 parents 2dee033 + 01f1df5 commit 53d0a56

File tree

13 files changed

+22
-125
lines changed

13 files changed

+22
-125
lines changed

CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
4444

4545
- The Signal Hunt activity no longer has a preview image, as it was not formatted correctly and spoiled the interior structure of the cave.
4646

47-
- `MovableObject`'s `UniqueID` field is now persisted through game save/load.
48-
4947
</details>
5048

5149
<details><summary><b>Fixed</b></summary>

Source/Entities/MovableObject.cpp

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ using namespace RTE;
2323

2424
AbstractClassInfo(MovableObject, SceneObject);
2525

26+
std::atomic<long> MovableObject::m_UniqueIDCounter = 1;
2627
std::string MovableObject::ms_EmptyString = "";
2728

2829
MovableObject::MovableObject() {
@@ -137,21 +138,17 @@ LuaStateWrapper& MovableObject::GetAndLockStateForScript(const std::string& scri
137138
}
138139

139140
int MovableObject::Create() {
140-
if (SceneObject::Create() < 0) {
141+
if (SceneObject::Create() < 0)
141142
return -1;
142-
}
143143

144+
m_AgeTimer.Reset();
144145
m_RestTimer.Reset();
145146

146147
// If the stop time hasn't been assigned, just make the same as the life time.
147-
if (m_EffectStopTime <= 0) {
148+
if (m_EffectStopTime <= 0)
148149
m_EffectStopTime = m_Lifetime;
149-
}
150150

151-
if (m_UniqueID == 0) {
152-
m_UniqueID = g_MovableMan.GetNextUniqueID();
153-
m_AgeTimer.Reset();
154-
}
151+
m_UniqueID = MovableObject::GetNextUniqueID();
155152

156153
m_MOIDHit = g_NoMOID;
157154
m_TerrainMatHit = g_MaterialAir;
@@ -180,7 +177,7 @@ int MovableObject::Create(const float mass,
180177
m_HitsMOs = hitMOs;
181178
m_GetsHitByMOs = getHitByMOs;
182179

183-
m_UniqueID = g_MovableMan.GetNextUniqueID();
180+
m_UniqueID = MovableObject::GetNextUniqueID();
184181

185182
m_MOIDHit = g_NoMOID;
186183
m_TerrainMatHit = g_MaterialAir;
@@ -206,6 +203,9 @@ int MovableObject::Create(const MovableObject& reference) {
206203
m_RestThreshold = reference.m_RestThreshold;
207204
// m_Force = reference.m_Force;
208205
// m_ImpulseForce = reference.m_ImpulseForce;
206+
// Should reset age instead??
207+
// m_AgeTimer = reference.m_AgeTimer;
208+
m_AgeTimer.Reset();
209209
m_RestTimer.Reset();
210210
m_Lifetime = reference.m_Lifetime;
211211
m_Sharpness = reference.m_Sharpness;
@@ -266,17 +266,7 @@ int MovableObject::Create(const MovableObject& reference) {
266266
m_NumberValueMap = reference.m_NumberValueMap;
267267
m_ObjectValueMap = reference.m_ObjectValueMap;
268268

269-
// If we're currently performing a game save or load we want to persist our existing IDs
270-
if (g_MovableMan.ShouldPersistUniqueIDs() && reference.m_UniqueID != 0) {
271-
m_UniqueID = reference.m_UniqueID;
272-
m_AgeTimer = reference.m_AgeTimer;
273-
const_cast<MovableObject&>(reference).m_UniqueID = 0; // fuck it, stop it deregistering us
274-
} else {
275-
// Otherwise we're copying from a preset normally and ought to create a new object
276-
m_UniqueID = g_MovableMan.GetNextUniqueID();
277-
m_AgeTimer.Reset();
278-
}
279-
269+
m_UniqueID = MovableObject::GetNextUniqueID();
280270
g_MovableMan.RegisterObject(this);
281271

282272
return 0;
@@ -384,7 +374,6 @@ int MovableObject::ReadProperty(const std::string_view& propName, Reader& reader
384374
MatchProperty("SimUpdatesBetweenScriptedUpdates", { reader >> m_SimUpdatesBetweenScriptedUpdates; });
385375
MatchProperty("AddCustomValue", { ReadCustomValueProperty(reader); });
386376
MatchProperty("ForceIntoMasterLuaState", { reader >> m_ForceIntoMasterLuaState; });
387-
MatchProperty("SpecialBehaviour_SetUniqueID", { reader >> m_UniqueID; });
388377

389378
EndPropertyList;
390379
}

Source/Entities/MovableObject.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -979,8 +979,9 @@ namespace RTE {
979979
/// @param newRestThreshold New rest threshold value
980980
void SetRestThreshold(int newRestThreshold) { m_RestThreshold = newRestThreshold; }
981981

982-
/// Resets this MO's unique persistent ID. Unsafe, only for internal use!
983-
void ResetUniqueID() { m_UniqueID = 0; }
982+
/// Returns the next unique id for MO's and increments unique ID counter
983+
/// @return Returns the next unique id.
984+
static long GetNextUniqueID() { return ++m_UniqueIDCounter; }
984985

985986
/// Returns this MO's unique persistent ID
986987
/// @return Returns this MO's unique persistent ID
@@ -1138,7 +1139,8 @@ namespace RTE {
11381139
/// @param A MovableObject object which is passed in by reference.
11391140
// Member variables
11401141
static Entity::ClassInfo m_sClass;
1141-
1142+
// Global counter with unique ID's
1143+
static std::atomic<long> m_UniqueIDCounter;
11421144
// The type of MO this is, either Actor, Item, or Particle
11431145
int m_MOType;
11441146
float m_Mass; // In metric kilograms (kg).

Source/Entities/Scene.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,6 @@ void Scene::SaveSceneObject(Writer& writer, const SceneObject* sceneObjectToSave
11671167
}
11681168

11691169
if (const MovableObject* movableObjectToSave = dynamic_cast<const MovableObject*>(sceneObjectToSave); movableObjectToSave && saveFullData) {
1170-
writer.NewPropertyWithValue("SpecialBehaviour_SetUniqueID", movableObjectToSave->GetUniqueID());
11711170
writer.NewPropertyWithValue("HUDVisible", movableObjectToSave->GetHUDVisible());
11721171
writer.NewPropertyWithValue("Velocity", movableObjectToSave->GetVel());
11731172
writer.NewPropertyWithValue("LifeTime", movableObjectToSave->GetLifetime());

Source/GUI/GUIReader.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,6 @@ GUIReader& GUIReader::operator>>(unsigned long& var) {
359359
return *this;
360360
}
361361

362-
GUIReader& GUIReader::operator>>(long long& var) {
363-
DiscardEmptySpace();
364-
*m_Stream >> var;
365-
return *this;
366-
}
367-
368362
// Yeah, this is dumb - read as double and cast.
369363
// This is because, for whatever fucking reason, iostream can save out floats at a precision that it's then unable to read...
370364
GUIReader& GUIReader::operator>>(float& var) {

Source/GUI/GUIReader.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ namespace RTE {
9292
GUIReader& operator>>(unsigned int& var);
9393
GUIReader& operator>>(long& var);
9494
GUIReader& operator>>(unsigned long& var);
95-
GUIReader& operator>>(long long& var);
9695
GUIReader& operator>>(float& var);
9796
GUIReader& operator>>(double& var);
9897
GUIReader& operator>>(std::string& var);

Source/Main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ void PollSDLEvents() {
245245
void RunMenuLoop() {
246246
g_UInputMan.DisableKeys(false);
247247
g_UInputMan.TrapMousePos(false);
248-
g_TimerMan.PauseSim(true);
249248

250249
while (!System::IsSetToQuit()) {
251250
g_WindowMan.ClearRenderer();

Source/Managers/ActivityMan.cpp

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ bool ActivityMan::SaveCurrentGame(const std::string& fileName) {
7676
m_SaveGameTask.wait();
7777
m_SaveGameTask = BS::multi_future<void>();
7878

79-
// Might not be strictly necessary?
80-
g_ThreadMan.GetPriorityThreadPool().wait_for_tasks();
81-
g_ThreadMan.GetBackgroundThreadPool().wait_for_tasks();
82-
8379
Scene* scene = g_SceneMan.GetScene();
8480
GAScripted* activity = dynamic_cast<GAScripted*>(GetActivity());
8581

@@ -97,9 +93,6 @@ bool ActivityMan::SaveCurrentGame(const std::string& fileName) {
9793
return false;
9894
}
9995

100-
long currentMaxID = g_MovableMan.GetMaxUniqueID();
101-
g_MovableMan.SetShouldPersistUniqueIDs(true);
102-
10396
// We need a copy of our scene, because we have to do some fixup to remove PLACEONLOAD items and only keep the current MovableMan state.
10497
std::unique_ptr<Scene> modifiableScene(dynamic_cast<Scene*>(scene->Clone()));
10598

@@ -132,8 +125,6 @@ bool ActivityMan::SaveCurrentGame(const std::string& fileName) {
132125
writer->NewPropertyWithValue("PlaceObjectsIfSceneIsRestarted", g_SceneMan.GetPlaceObjectsOnLoad());
133126
writer->NewPropertyWithValue("PlaceUnitsIfSceneIsRestarted", g_SceneMan.GetPlaceUnitsOnLoad());
134127
writer->NewPropertyWithValue("Scene", modifiableScene.get());
135-
writer->NewPropertyWithValue("MaxUniqueID", currentMaxID);
136-
writer->NewPropertyWithValue("CurrentSimTicks", g_TimerMan.GetSimTickCount());
137128

138129
auto saveWriterData = [](Writer* writerToSave) {
139130
writerToSave->EndWrite();
@@ -146,18 +137,13 @@ bool ActivityMan::SaveCurrentGame(const std::string& fileName) {
146137
// We didn't transfer ownership, so we must be very careful that sceneAltered's deletion doesn't touch the stuff we got from MovableMan.
147138
modifiableScene->ClearPlacedObjectSet(Scene::PlacedObjectSets::PLACEONLOAD, false);
148139

149-
g_MovableMan.SetShouldPersistUniqueIDs(false);
150-
151140
g_ConsoleMan.PrintString("SYSTEM: Game saved to \"" + fileName + "\"!");
152141
return true;
153142
}
154143

155144
bool ActivityMan::LoadAndLaunchGame(const std::string& fileName) {
156145
m_SaveGameTask.wait();
157146

158-
g_ThreadMan.GetPriorityThreadPool().wait_for_tasks();
159-
g_ThreadMan.GetBackgroundThreadPool().wait_for_tasks();
160-
161147
std::string saveFilePath = g_PresetMan.GetFullModulePath(c_UserScriptedSavesModuleName) + "/" + fileName + "/Save.ini";
162148

163149
if (!std::filesystem::exists(saveFilePath)) {
@@ -170,12 +156,6 @@ bool ActivityMan::LoadAndLaunchGame(const std::string& fileName) {
170156
std::unique_ptr<Scene> scene(std::make_unique<Scene>());
171157
std::unique_ptr<GAScripted> activity(std::make_unique<GAScripted>());
172158

173-
g_MovableMan.ClearKnownObjects();
174-
175-
g_MovableMan.SetMaxUniqueID(std::numeric_limits<long>::min());
176-
177-
long maxUniqueID = 1;
178-
long long simTimeTicks = 0;
179159
std::string originalScenePresetName = fileName;
180160
bool placeObjectsIfSceneIsRestarted = true;
181161
bool placeUnitsIfSceneIsRestarted = true;
@@ -191,35 +171,20 @@ bool ActivityMan::LoadAndLaunchGame(const std::string& fileName) {
191171
reader >> placeUnitsIfSceneIsRestarted;
192172
} else if (propName == "Scene") {
193173
reader >> scene.get();
194-
} else if (propName == "MaxUniqueID") {
195-
reader >> maxUniqueID;
196-
} else if (propName == "CurrentSimTicks") {
197-
reader >> simTimeTicks;
198-
}
174+
}
199175
}
200176

201-
g_MovableMan.SetShouldPersistUniqueIDs(true);
202-
203177
// SetSceneToLoad() doesn't Clone(), but when the Activity starts, it will eventually call LoadScene(), which does a Clone() of scene internally.
204178
g_SceneMan.SetSceneToLoad(scene.get(), true, true);
205179
// Saved Scenes get their presetname set to their filename to ensure they're separate from the preset Scene they're based off of.
206180
// However, saving a game you've already saved will end up with its OriginalScenePresetName set to the filename, which will screw up restarting the Activity, so we set its PresetName here.
207181
scene->SetPresetName(originalScenePresetName);
208182
// For starting Activity, we need to directly clone the Activity we want to start.
209183
StartActivity(dynamic_cast<GAScripted*>(activity->Clone()));
210-
211-
g_MovableMan.SetShouldPersistUniqueIDs(false);
212-
213-
// Set the max unique ID to our loaded maximum so we don't stomp over any existing ones
214-
g_MovableMan.SetMaxUniqueID(maxUniqueID);
215-
216-
//g_TimerMan.SetSimTickCount(simTimeTicks); // Don't do for now... causes issues with negative times in places
217-
218184
// When this method exits, our Scene object will be destroyed, which will cause problems if you try to restart it. To avoid this, set the Scene to load to the preset object with the same name.
219185
g_SceneMan.SetSceneToLoad(originalScenePresetName, placeObjectsIfSceneIsRestarted, placeUnitsIfSceneIsRestarted);
220186

221187
g_ConsoleMan.PrintString("SYSTEM: Game \"" + fileName + "\" loaded!");
222-
223188
return true;
224189
}
225190

Source/Managers/MovableMan.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ struct MOXPosComparison {
4343

4444
MovableMan::MovableMan() {
4545
Clear();
46-
m_UniqueIDCounter = 1;
4746
}
4847

4948
MovableMan::~MovableMan() {
@@ -76,7 +75,6 @@ void MovableMan::Clear() {
7675
m_MaxDroppedItems = 100;
7776
m_SettlingEnabled = true;
7877
m_MOSubtractionEnabled = true;
79-
m_ShouldPersistUniqueIDs = false;
8078
}
8179

8280
int MovableMan::Initialize() {
@@ -166,7 +164,7 @@ MOID MovableMan::GetMOIDPixel(int pixelX, int pixelY, const std::vector<int>& mo
166164
}
167165

168166
void MovableMan::RegisterObject(MovableObject* mo) {
169-
if (!mo || mo->GetUniqueID() <= 0) {
167+
if (!mo) {
170168
return;
171169
}
172170

@@ -183,14 +181,6 @@ void MovableMan::UnregisterObject(MovableObject* mo) {
183181
m_KnownObjects.erase(mo->GetUniqueID());
184182
}
185183

186-
void RTE::MovableMan::ClearKnownObjects() {
187-
for (auto& pair : m_KnownObjects) {
188-
pair.second->ResetUniqueID();
189-
}
190-
191-
m_KnownObjects.clear();
192-
}
193-
194184
const std::vector<MovableObject*>* MovableMan::GetMOsInBox(const Box& box, int ignoreTeam, bool getsHitByMOsOnly) const {
195185
std::vector<MovableObject*>* vectorForLua = new std::vector<MovableObject*>();
196186
*vectorForLua = std::move(g_SceneMan.GetMOIDGrid().GetMOsInBox(box, ignoreTeam, getsHitByMOsOnly));

Source/Managers/MovableMan.h

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -482,38 +482,14 @@ namespace RTE {
482482
/// @param mo MO to remove.
483483
void UnregisterObject(MovableObject* mo);
484484

485-
/// Returns the next unique id for MO's and increments unique ID counter
486-
/// @return Returns the next unique id.
487-
long GetNextUniqueID() { return ++m_UniqueIDCounter; }
488-
489-
/// Returns the max unique id for MO's
490-
/// @return Returns the current max unique id.
491-
long GetMaxUniqueID() { return m_UniqueIDCounter; }
492-
493-
/// Set the max unique id for MO's. This is used so we can consistently save/load unique IDs so they're consistent within a game session
494-
/// @param id Unique Id to set.
495-
void SetMaxUniqueID(long newMaxID) { m_UniqueIDCounter = newMaxID; }
496-
497-
/// Returns whether we should be persisting uniqueIDs for save/load
498-
/// @return Returns whether we are persisting uniqueIDs.
499-
bool ShouldPersistUniqueIDs() { return m_ShouldPersistUniqueIDs; }
500-
501-
/// Sets whether we should be persisting uniqueIDs for save/load
502-
/// @param newValue Whether we should be persisting uniqueIDs.
503-
void SetShouldPersistUniqueIDs(bool newValue) { m_ShouldPersistUniqueIDs = newValue; }
504-
505-
/// Clears all known objects. Should only be used for internal usage, it's unsafe!
506-
void ClearKnownObjects();
507-
508485
/// Uses a global lookup map to find an object by it's unique id.
509486
/// @param id Unique Id to look for.
510487
/// @return Object found or 0 if not found any.
511-
MovableObject* FindObjectByUniqueID(long id) {
512-
if (m_KnownObjects.count(id) > 0) {
488+
MovableObject* FindObjectByUniqueID(long int id) {
489+
if (m_KnownObjects.count(id) > 0)
513490
return m_KnownObjects[id];
514-
} else {
491+
else
515492
return 0;
516-
}
517493
}
518494

519495
/// Returns the size of the object registry collection
@@ -575,10 +551,6 @@ namespace RTE {
575551
std::deque<Actor*> m_Actors;
576552
// A map to give a unique contiguous identifier per-actor. This is re-created per frame.
577553
std::unordered_map<const Actor*, int> m_ContiguousActorIDs;
578-
// Global counter with unique ID's
579-
std::atomic<long> m_UniqueIDCounter;
580-
// Whether or not UniqueIDs should be persisted (for save/load)
581-
bool m_ShouldPersistUniqueIDs;
582554
// List of items that are pickup-able by actors
583555
std::deque<MovableObject*> m_Items;
584556
// List of free, dead particles flying around
@@ -649,8 +621,8 @@ namespace RTE {
649621

650622
unsigned int m_SimUpdateFrameNumber;
651623

652-
// Global map which stores all objects so they could be found by their unique ID
653-
std::map<long, MovableObject*> m_KnownObjects;
624+
// Global map which stores all objects so they could be foud by their unique ID
625+
std::map<long int, MovableObject*> m_KnownObjects;
654626

655627
/// Private member variable and method declarations
656628
private:

0 commit comments

Comments
 (0)