Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit b54d058

Browse files
committed
Made saving in editors (scene editor and area editor) not save all data so they don't get bloated with irrelevant stuff that's only needed for game saves
1 parent 89cc15f commit b54d058

File tree

2 files changed

+107
-76
lines changed

2 files changed

+107
-76
lines changed

Entities/Scene.cpp

Lines changed: 105 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "BunkerAssemblyScheme.h"
2929
#include "BunkerAssembly.h"
3030
#include "SLBackground.h"
31+
#include "EditorActivity.h"
3132

3233
#include "AEmitter.h"
3334
#include "ADoor.h"
@@ -1333,6 +1334,9 @@ int Scene::ReadProperty(const std::string_view &propName, Reader &reader)
13331334

13341335
int Scene::Save(Writer &writer) const {
13351336
Entity::Save(writer);
1337+
1338+
bool doFullGameSave = !dynamic_cast<EditorActivity *>(g_ActivityMan.GetActivity());
1339+
13361340
writer.NewPropertyWithValue("LocationOnPlanet", m_Location);
13371341
writer.NewPropertyWithValue("MetagamePlayable", m_MetagamePlayable);
13381342
//Do not save preview if it's path is empty, for example in metagame
@@ -1354,9 +1358,10 @@ int Scene::Save(Writer &writer) const {
13541358
writer.NewPropertyWithValue(playerNumberString + "BuildBudgetRatio", m_BuildBudgetRatio[player]);
13551359
if (m_ResidentBrains[player]) {
13561360
writer.NewProperty(playerNumberString + "ResidentBrain");
1357-
SaveSceneObject(writer, m_ResidentBrains[player], false);
1361+
SaveSceneObject(writer, m_ResidentBrains[player], false, doFullGameSave);
13581362
}
13591363
}
1364+
13601365
writer.NewPropertyWithValue("AutoDesigned", m_AutoDesigned);
13611366
writer.NewPropertyWithValue("TotalInvestment", m_TotalInvestment);
13621367
writer.NewPropertyWithValue("Terrain", m_pTerrain);
@@ -1379,7 +1384,7 @@ int Scene::Save(Writer &writer) const {
13791384
}
13801385

13811386
//writer << placedObject;
1382-
SaveSceneObject(writer, placedObject, false);
1387+
SaveSceneObject(writer, placedObject, false, doFullGameSave);
13831388
}
13841389
}
13851390

@@ -1465,11 +1470,11 @@ int Scene::Save(Writer &writer) const {
14651470

14661471
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
14671472

1468-
void Scene::SaveSceneObject(Writer &writer, const SceneObject *sceneObjectToSave, bool isChildAttachable) const {
1469-
auto WriteHardcodedAttachableOrNone = [this, &writer](const std::string &propertyName, const Attachable *harcodedAttachable) {
1473+
void Scene::SaveSceneObject(Writer &writer, const SceneObject *sceneObjectToSave, bool isChildAttachable, bool saveFullData) const {
1474+
auto WriteHardcodedAttachableOrNone = [this, &writer, &saveFullData](const std::string &propertyName, const Attachable *harcodedAttachable) {
14701475
if (harcodedAttachable) {
14711476
writer.NewProperty(propertyName);
1472-
SaveSceneObject(writer, harcodedAttachable, true);
1477+
SaveSceneObject(writer, harcodedAttachable, true, saveFullData);
14731478
} else {
14741479
writer.NewPropertyWithValue(propertyName, "None");
14751480
}
@@ -1478,22 +1483,26 @@ void Scene::SaveSceneObject(Writer &writer, const SceneObject *sceneObjectToSave
14781483
writer.ObjectStart(sceneObjectToSave->GetClassName());
14791484
writer.NewPropertyWithValue("CopyOf", sceneObjectToSave->GetModuleAndPresetName());
14801485

1481-
for (const std::string &group : *sceneObjectToSave->GetGroups()) {
1482-
writer.NewPropertyWithValue("AddToGroup", group);
1486+
if (saveFullData) {
1487+
for (const std::string &group : *sceneObjectToSave->GetGroups()) {
1488+
writer.NewPropertyWithValue("AddToGroup", group);
1489+
}
14831490
}
14841491

14851492
writer.NewPropertyWithValue("Position", sceneObjectToSave->GetPos());
14861493
writer.NewPropertyWithValue("Team", sceneObjectToSave->GetTeam());
14871494
if (!isChildAttachable) {
14881495
writer.NewPropertyWithValue("PlacedByPlayer", sceneObjectToSave->GetPlacedByPlayer());
14891496
}
1490-
writer.NewPropertyWithValue("GoldValue", sceneObjectToSave->GetGoldValue());
1497+
if (saveFullData) {
1498+
writer.NewPropertyWithValue("GoldValue", sceneObjectToSave->GetGoldValue());
1499+
}
14911500

14921501
if (const Deployment *deploymentToSave = dynamic_cast<const Deployment *>(sceneObjectToSave); deploymentToSave && deploymentToSave->GetID() != 0) {
14931502
writer.NewPropertyWithValue("ID", deploymentToSave->GetID());
14941503
}
14951504

1496-
if (const MovableObject *movableObjectToSave = dynamic_cast<const MovableObject *>(sceneObjectToSave)) {
1505+
if (const MovableObject *movableObjectToSave = dynamic_cast<const MovableObject *>(sceneObjectToSave); movableObjectToSave && saveFullData) {
14971506
writer.NewPropertyWithValue("HUDVisible", movableObjectToSave->GetHUDVisible());
14981507
writer.NewPropertyWithValue("Velocity", movableObjectToSave->GetVel());
14991508
writer.NewPropertyWithValue("LifeTime", movableObjectToSave->GetLifetime());
@@ -1503,30 +1512,37 @@ void Scene::SaveSceneObject(Writer &writer, const SceneObject *sceneObjectToSave
15031512

15041513
if (const MOSprite *moSpriteToSave = dynamic_cast<const MOSprite *>(sceneObjectToSave)) {
15051514
writer.NewPropertyWithValue("HFlipped", moSpriteToSave->IsHFlipped());
1506-
writer.NewPropertyWithValue("Rotation", moSpriteToSave->GetRotMatrix());
1507-
writer.NewPropertyWithValue("AngularVel", moSpriteToSave->GetAngularVel());
1515+
if (saveFullData || dynamic_cast<const ADoor *>(moSpriteToSave)) {
1516+
writer.NewPropertyWithValue("Rotation", moSpriteToSave->GetRotMatrix());
1517+
}
1518+
if (saveFullData) {
1519+
writer.NewPropertyWithValue("AngularVel", moSpriteToSave->GetAngularVel());
1520+
}
15081521
}
15091522

15101523
if (const MOSRotating *mosRotatingToSave = dynamic_cast<const MOSRotating *>(sceneObjectToSave)) {
1511-
const std::list<Attachable *> &attachablesToSave = mosRotatingToSave->GetAttachableList();
1512-
1513-
// If this MOSRotating has any Attachables, we have to add a special behaviour property that'll delete them all so they can be re-read. This will allow us to handle Attachables with our limited serialization.
1514-
// Alternatively, if the MOSRotating has no Attachables but its preset does, we need to set the flag, because that means this is missing Attachables, and we don't want to magically regenerate them when a game is loaded.
1515-
if (!attachablesToSave.empty()) {
1516-
writer.NewPropertyWithValue("SpecialBehaviour_ClearAllAttachables", true);
1517-
} else if (const MOSRotating *presetOfMOSRotatingToSave = dynamic_cast<const MOSRotating *>(g_PresetMan.GetEntityPreset(mosRotatingToSave->GetClassName(), mosRotatingToSave->GetPresetName(), mosRotatingToSave->GetModuleID())); presetOfMOSRotatingToSave && !presetOfMOSRotatingToSave->GetAttachableList().empty()) {
1518-
writer.NewPropertyWithValue("SpecialBehaviour_ClearAllAttachables", true);
1519-
}
1524+
if (saveFullData) {
1525+
const std::list<Attachable *> &attachablesToSave = mosRotatingToSave->GetAttachableList();
15201526

1521-
for (const Attachable *attachable : attachablesToSave) {
1522-
if (!mosRotatingToSave->AttachableIsHardcoded(attachable)) {
1523-
writer.NewProperty("AddAttachable");
1524-
SaveSceneObject(writer, attachable, true);
1527+
// If this MOSRotating has any Attachables, we have to add a special behaviour property that'll delete them all so they can be re-read. This will allow us to handle Attachables with our limited serialization.
1528+
// Alternatively, if the MOSRotating has no Attachables but its preset does, we need to set the flag, because that means this is missing Attachables, and we don't want to magically regenerate them when a game is loaded.
1529+
if (!attachablesToSave.empty()) {
1530+
writer.NewPropertyWithValue("SpecialBehaviour_ClearAllAttachables", true);
1531+
}
1532+
else if (const MOSRotating *presetOfMOSRotatingToSave = dynamic_cast<const MOSRotating *>(g_PresetMan.GetEntityPreset(mosRotatingToSave->GetClassName(), mosRotatingToSave->GetPresetName(), mosRotatingToSave->GetModuleID())); presetOfMOSRotatingToSave && !presetOfMOSRotatingToSave->GetAttachableList().empty()) {
1533+
writer.NewPropertyWithValue("SpecialBehaviour_ClearAllAttachables", true);
1534+
}
1535+
1536+
for (const Attachable *attachable : attachablesToSave) {
1537+
if (!mosRotatingToSave->AttachableIsHardcoded(attachable)) {
1538+
writer.NewProperty("AddAttachable");
1539+
SaveSceneObject(writer, attachable, true, saveFullData);
1540+
}
1541+
}
1542+
for (const AEmitter *wound : mosRotatingToSave->GetWoundList()) {
1543+
writer.NewProperty("SpecialBehaviour_AddWound");
1544+
SaveSceneObject(writer, wound, true, saveFullData);
15251545
}
1526-
}
1527-
for (const AEmitter *wound : mosRotatingToSave->GetWoundList()) {
1528-
writer.NewProperty("SpecialBehaviour_AddWound");
1529-
SaveSceneObject(writer, wound, true);
15301546
}
15311547

15321548
for (auto &[key, value] : mosRotatingToSave->GetStringValueMap()) {
@@ -1544,7 +1560,7 @@ void Scene::SaveSceneObject(Writer &writer, const SceneObject *sceneObjectToSave
15441560
}
15451561
}
15461562

1547-
if (const Attachable *attachableToSave = dynamic_cast<const Attachable *>(sceneObjectToSave)) {
1563+
if (const Attachable *attachableToSave = dynamic_cast<const Attachable *>(sceneObjectToSave); attachableToSave && saveFullData) {
15481564
writer.NewPropertyWithValue("ParentOffset", attachableToSave->GetParentOffset());
15491565
writer.NewPropertyWithValue("DrawAfterParent", attachableToSave->IsDrawnAfterParent());
15501566
writer.NewPropertyWithValue("DeleteWhenRemovedFromParent", attachableToSave->GetDeleteWhenRemovedFromParent());
@@ -1606,23 +1622,26 @@ void Scene::SaveSceneObject(Writer &writer, const SceneObject *sceneObjectToSave
16061622
}
16071623

16081624
if (const Actor *actorToSave = dynamic_cast<const Actor *>(sceneObjectToSave)) {
1609-
writer.NewPropertyWithValue("Status", actorToSave->GetStatus());
16101625
writer.NewPropertyWithValue("Health", actorToSave->GetHealth());
16111626
writer.NewPropertyWithValue("MaxHealth", actorToSave->GetMaxHealth());
1612-
writer.NewPropertyWithValue("PlayerControllable", actorToSave->IsPlayerControllable());
1613-
int aiModeToSave = actorToSave->GetAIMode() == Actor::AIMode::AIMODE_SQUAD ? Actor::AIMode::AIMODE_GOTO : actorToSave->GetAIMode();
1614-
if (aiModeToSave == Actor::AIMode::AIMODE_GOTO && (!actorToSave->GetMOMoveTarget() && g_SceneMan.ShortestDistance(actorToSave->GetMovePathEnd(), actorToSave->GetPos(), g_SceneMan.SceneWrapsX()).MagnitudeIsLessThan(1.0F))) {
1615-
aiModeToSave = Actor::AIMode::AIMODE_SENTRY;
1616-
}
1617-
writer.NewPropertyWithValue("AIMode", aiModeToSave);
1618-
if (aiModeToSave == Actor::AIMode::AIMODE_GOTO) {
1619-
const std::string addWaypointPropertyName = "SpecialBehaviour_AddAISceneWaypoint";
1620-
if (const MovableObject *actorToSaveMOMoveTarget = actorToSave->GetMOMoveTarget()) {
1621-
writer.NewPropertyWithValue(addWaypointPropertyName, actorToSaveMOMoveTarget->GetPos());
1622-
} else {
1623-
writer.NewPropertyWithValue(addWaypointPropertyName, actorToSave->GetMovePathEnd());
1624-
for (auto &[waypointPosition, waypointObject] : actorToSave->GetWaypointList()) {
1625-
writer.NewPropertyWithValue(addWaypointPropertyName, waypointPosition);
1627+
if (saveFullData) {
1628+
writer.NewPropertyWithValue("Status", actorToSave->GetStatus());
1629+
writer.NewPropertyWithValue("PlayerControllable", actorToSave->IsPlayerControllable());
1630+
1631+
int aiModeToSave = actorToSave->GetAIMode() == Actor::AIMode::AIMODE_SQUAD ? Actor::AIMode::AIMODE_GOTO : actorToSave->GetAIMode();
1632+
if (aiModeToSave == Actor::AIMode::AIMODE_GOTO && (!actorToSave->GetMOMoveTarget() && g_SceneMan.ShortestDistance(actorToSave->GetMovePathEnd(), actorToSave->GetPos(), g_SceneMan.SceneWrapsX()).MagnitudeIsLessThan(1.0F))) {
1633+
aiModeToSave = Actor::AIMode::AIMODE_SENTRY;
1634+
}
1635+
writer.NewPropertyWithValue("AIMode", aiModeToSave);
1636+
if (aiModeToSave == Actor::AIMode::AIMODE_GOTO) {
1637+
const std::string addWaypointPropertyName = "SpecialBehaviour_AddAISceneWaypoint";
1638+
if (const MovableObject *actorToSaveMOMoveTarget = actorToSave->GetMOMoveTarget()) {
1639+
writer.NewPropertyWithValue(addWaypointPropertyName, actorToSaveMOMoveTarget->GetPos());
1640+
} else {
1641+
writer.NewPropertyWithValue(addWaypointPropertyName, actorToSave->GetMovePathEnd());
1642+
for (auto &[waypointPosition, waypointObject] : actorToSave->GetWaypointList()) {
1643+
writer.NewPropertyWithValue(addWaypointPropertyName, waypointPosition);
1644+
}
16261645
}
16271646
}
16281647
}
@@ -1633,40 +1652,51 @@ void Scene::SaveSceneObject(Writer &writer, const SceneObject *sceneObjectToSave
16331652

16341653
for (const MovableObject *inventoryItem : *actorToSave->GetInventory()) {
16351654
writer.NewProperty("AddInventory");
1636-
SaveSceneObject(writer, inventoryItem, true);
1655+
SaveSceneObject(writer, inventoryItem, true, saveFullData);
16371656
}
16381657

1639-
if (const ADoor *aDoorToSave = dynamic_cast<const ADoor *>(sceneObjectToSave)) {
1640-
WriteHardcodedAttachableOrNone("Door", aDoorToSave->GetDoor());
1658+
if (saveFullData) {
1659+
if (const ADoor *aDoorToSave = dynamic_cast<const ADoor *>(sceneObjectToSave)) {
1660+
WriteHardcodedAttachableOrNone("Door", aDoorToSave->GetDoor());
1661+
} else if (const AHuman *aHumanToSave = dynamic_cast<const AHuman *>(sceneObjectToSave)) {
1662+
WriteHardcodedAttachableOrNone("Head", aHumanToSave->GetHead());
1663+
WriteHardcodedAttachableOrNone("Jetpack", aHumanToSave->GetJetpack());
1664+
WriteHardcodedAttachableOrNone("FGArm", aHumanToSave->GetFGArm());
1665+
WriteHardcodedAttachableOrNone("BGArm", aHumanToSave->GetBGArm());
1666+
WriteHardcodedAttachableOrNone("FGLeg", aHumanToSave->GetFGLeg());
1667+
WriteHardcodedAttachableOrNone("BGLeg", aHumanToSave->GetBGLeg());
1668+
} else if (const ACrab *aCrabToSave = dynamic_cast<const ACrab *>(sceneObjectToSave)) {
1669+
WriteHardcodedAttachableOrNone("Turret", aCrabToSave->GetTurret());
1670+
WriteHardcodedAttachableOrNone("Jetpack", aCrabToSave->GetJetpack());
1671+
WriteHardcodedAttachableOrNone("LeftFGLeg", aCrabToSave->GetLeftFGLeg());
1672+
WriteHardcodedAttachableOrNone("LeftBGLeg", aCrabToSave->GetLeftBGLeg());
1673+
WriteHardcodedAttachableOrNone("RightFGLeg", aCrabToSave->GetRightFGLeg());
1674+
WriteHardcodedAttachableOrNone("RightBGLeg", aCrabToSave->GetRightBGLeg());
1675+
} else if (const ACRocket *acRocketToSave = dynamic_cast<const ACRocket *>(sceneObjectToSave)) {
1676+
WriteHardcodedAttachableOrNone("RightLeg", acRocketToSave->GetRightLeg());
1677+
WriteHardcodedAttachableOrNone("LeftLeg", acRocketToSave->GetLeftLeg());
1678+
WriteHardcodedAttachableOrNone("MainThruster", acRocketToSave->GetMainThruster());
1679+
WriteHardcodedAttachableOrNone("RightThruster", acRocketToSave->GetRightThruster());
1680+
WriteHardcodedAttachableOrNone("LeftThruster", acRocketToSave->GetLeftThruster());
1681+
WriteHardcodedAttachableOrNone("UpRightThruster", acRocketToSave->GetURightThruster());
1682+
WriteHardcodedAttachableOrNone("UpRightThruster", acRocketToSave->GetULeftThruster());
1683+
} else if (const ACDropShip *acDropShipToSave = dynamic_cast<const ACDropShip *>(sceneObjectToSave)) {
1684+
WriteHardcodedAttachableOrNone("RightThruster", acDropShipToSave->GetRightThruster());
1685+
WriteHardcodedAttachableOrNone("LeftThruster", acDropShipToSave->GetLeftThruster());
1686+
WriteHardcodedAttachableOrNone("UpRightThruster", acDropShipToSave->GetURightThruster());
1687+
WriteHardcodedAttachableOrNone("UpLeftThruster", acDropShipToSave->GetULeftThruster());
1688+
WriteHardcodedAttachableOrNone("RightHatchDoor", acDropShipToSave->GetRightHatch());
1689+
WriteHardcodedAttachableOrNone("LeftHatchDoor", acDropShipToSave->GetLeftHatch());
1690+
}
16411691
} else if (const AHuman *aHumanToSave = dynamic_cast<const AHuman *>(sceneObjectToSave)) {
1642-
WriteHardcodedAttachableOrNone("Head", aHumanToSave->GetHead());
1643-
WriteHardcodedAttachableOrNone("Jetpack", aHumanToSave->GetJetpack());
1644-
WriteHardcodedAttachableOrNone("FGArm", aHumanToSave->GetFGArm());
1645-
WriteHardcodedAttachableOrNone("BGArm", aHumanToSave->GetBGArm());
1646-
WriteHardcodedAttachableOrNone("FGLeg", aHumanToSave->GetFGLeg());
1647-
WriteHardcodedAttachableOrNone("BGLeg", aHumanToSave->GetBGLeg());
1648-
} else if (const ACrab *aCrabToSave = dynamic_cast<const ACrab *>(sceneObjectToSave)) {
1649-
WriteHardcodedAttachableOrNone("Turret", aCrabToSave->GetTurret());
1650-
WriteHardcodedAttachableOrNone("Jetpack", aCrabToSave->GetJetpack());
1651-
WriteHardcodedAttachableOrNone("LeftFGLeg", aCrabToSave->GetLeftFGLeg());
1652-
WriteHardcodedAttachableOrNone("LeftBGLeg", aCrabToSave->GetLeftBGLeg());
1653-
WriteHardcodedAttachableOrNone("RightFGLeg", aCrabToSave->GetRightFGLeg());
1654-
WriteHardcodedAttachableOrNone("RightBGLeg", aCrabToSave->GetRightBGLeg());
1655-
} else if (const ACRocket *acRocketToSave = dynamic_cast<const ACRocket *>(sceneObjectToSave)) {
1656-
WriteHardcodedAttachableOrNone("RightLeg", acRocketToSave->GetRightLeg());
1657-
WriteHardcodedAttachableOrNone("LeftLeg", acRocketToSave->GetLeftLeg());
1658-
WriteHardcodedAttachableOrNone("MainThruster", acRocketToSave->GetMainThruster());
1659-
WriteHardcodedAttachableOrNone("RightThruster", acRocketToSave->GetRightThruster());
1660-
WriteHardcodedAttachableOrNone("LeftThruster", acRocketToSave->GetLeftThruster());
1661-
WriteHardcodedAttachableOrNone("UpRightThruster", acRocketToSave->GetURightThruster());
1662-
WriteHardcodedAttachableOrNone("UpRightThruster", acRocketToSave->GetULeftThruster());
1663-
} else if (const ACDropShip *acDropShipToSave = dynamic_cast<const ACDropShip *>(sceneObjectToSave)) {
1664-
WriteHardcodedAttachableOrNone("RightThruster", acDropShipToSave->GetRightThruster());
1665-
WriteHardcodedAttachableOrNone("LeftThruster", acDropShipToSave->GetLeftThruster());
1666-
WriteHardcodedAttachableOrNone("UpRightThruster", acDropShipToSave->GetURightThruster());
1667-
WriteHardcodedAttachableOrNone("UpLeftThruster", acDropShipToSave->GetULeftThruster());
1668-
WriteHardcodedAttachableOrNone("RightHatchDoor", acDropShipToSave->GetRightHatch());
1669-
WriteHardcodedAttachableOrNone("LeftHatchDoor", acDropShipToSave->GetLeftHatch());
1692+
if (const HeldDevice *equippedItem = aHumanToSave->GetEquippedItem()) {
1693+
writer.NewProperty("AddInventory");
1694+
SaveSceneObject(writer, equippedItem, true, saveFullData);
1695+
}
1696+
if (const HeldDevice *bgEquippedItem = aHumanToSave->GetEquippedBGItem()) {
1697+
writer.NewProperty("AddInventory");
1698+
SaveSceneObject(writer, bgEquippedItem, true, saveFullData);
1699+
}
16701700
}
16711701
}
16721702
writer.ObjectEnd();

Entities/Scene.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,8 @@ const SceneObject * PickPlacedActorInRange(int whichSet, Vector &scenePoint, int
14031403
/// <param name="writer">The Writer being used for serialization.</param>
14041404
/// <param name="sceneObjectToSave">The SceneObject to save.</param>
14051405
/// <param name="isChildAttachable">Convenience flag for whether or not this SceneObject is a child Attachable, and certain properties shouldn't be saved.</param>
1406-
void SaveSceneObject(Writer &writer, const SceneObject *sceneObjectToSave, bool isChildAttachable) const;
1406+
/// <param name="saveFullData">Whether or not to save most data. Turned off for stuff like SceneEditor saves.</param>
1407+
void SaveSceneObject(Writer &writer, const SceneObject *sceneObjectToSave, bool isChildAttachable, bool saveFullData) const;
14071408

14081409
//////////////////////////////////////////////////////////////////////////////////////////
14091410
// Method: Clear

0 commit comments

Comments
 (0)