- cut down on data size by not saving trivial defaults.

This commit is contained in:
Christoph Oelckers 2016-09-18 16:41:34 +02:00
parent 9313a99e12
commit a5628518c1
2 changed files with 218 additions and 174 deletions

View file

@ -23,6 +23,10 @@
#include "r_data/r_interpolate.h" #include "r_data/r_interpolate.h"
#include "g_shared/a_sharedglobal.h" #include "g_shared/a_sharedglobal.h"
TArray<sector_t> loadsectors;
TArray<line_t> loadlines;
TArray<side_t> loadsides;
//========================================================================== //==========================================================================
// //
// //
@ -192,7 +196,7 @@ public:
return *this; return *this;
} }
FSerializer &BeginArray(const char *name) bool BeginArray(const char *name)
{ {
if (isWriting()) if (isWriting())
{ {
@ -216,10 +220,10 @@ public:
} }
else else
{ {
I_Error("'%s' not found", name); return false;
} }
} }
return *this; return true;
} }
FSerializer &EndArray() FSerializer &EndArray()
@ -302,15 +306,25 @@ public:
return Serialize(*this, key, obj); return Serialize(*this, key, obj);
} }
template<class T>
FSerializer &operator()(const char *key, T &obj, T & def)
{
if (isWriting() && !memcmp(&obj, &def, sizeof(T))) return *this;
return Serialize(*this, key, obj);
}
template<class T> template<class T>
FSerializer &Array(const char *key, T *obj, int count) FSerializer &Array(const char *key, T *obj, int count)
{ {
BeginArray(key); if (BeginArray(key))
for (int i = 0; i < count; i++)
{ {
Serialize(*this, nullptr, obj[i]); for (int i = 0; i < count; i++)
{
Serialize(*this, nullptr, obj[i]);
}
EndArray();
} }
return EndArray(); return *this;
} }
FSerializer &Terrain(const char *key, int &terrain) FSerializer &Terrain(const char *key, int &terrain)
@ -720,9 +734,9 @@ FSerializer &Serialize(FSerializer &arc, const char *key, DObject *&value)
{ {
if (arc.isWriting()) if (arc.isWriting())
{ {
int ndx = -1;
if (value != nullptr) if (value != nullptr)
{ {
int ndx;
int *pndx = arc.mObjectMap.CheckKey(value); int *pndx = arc.mObjectMap.CheckKey(value);
if (pndx != nullptr) ndx = *pndx; if (pndx != nullptr) ndx = *pndx;
else else
@ -730,11 +744,19 @@ FSerializer &Serialize(FSerializer &arc, const char *key, DObject *&value)
ndx = arc.mDObjects.Push(value); ndx = arc.mDObjects.Push(value);
arc.mObjectMap[value] = ndx; arc.mObjectMap[value] = ndx;
} }
Serialize(arc, key, ndx);
} }
Serialize(arc, key, ndx);
} }
else else
{ {
auto val = arc.FindKey(key);
if (val != nullptr)
{
}
else
{
value = nullptr;
}
} }
return arc; return arc;
} }
@ -760,9 +782,18 @@ FSerializer &Serialize(FSerializer &arc, const char *key, TObjPtr<T> &value)
template<class T, class TT> template<class T, class TT>
FSerializer &Serialize(FSerializer &arc, const char *key, TArray<T, TT> &value) FSerializer &Serialize(FSerializer &arc, const char *key, TArray<T, TT> &value)
{ {
arc.BeginArray(key); if (arc.isWriting())
{
if (value.Size() == 0) return arc; // do not save empty arrays
}
bool res = arc.BeginArray(key);
if (arc.isReading()) if (arc.isReading())
{ {
if (!res)
{
value.Clear();
return arc;
}
value.Resize(arc.ArraySize()); value.Resize(arc.ArraySize());
} }
for (unsigned i = 0; i < value.Size(); i++) for (unsigned i = 0; i < value.Size(); i++)
@ -833,7 +864,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, line_t &line)
("alpha", line.alpha) ("alpha", line.alpha)
.Args("args", line.args, line.special) .Args("args", line.args, line.special)
("portalindex", line.portalindex) ("portalindex", line.portalindex)
.Array("sides", line.sidedef, 2) //.Array("sides", line.sidedef, 2)
.EndObject(); .EndObject();
// no need to store the sidedef references. Unless the map loader is changed they will not change between map loads. // no need to store the sidedef references. Unless the map loader is changed they will not change between map loads.
@ -869,9 +900,9 @@ FSerializer &Serialize(FSerializer &arc, const char *key, side_t &side)
.Array("textures", side.textures, 3) .Array("textures", side.textures, 3)
("light", side.Light) ("light", side.Light)
("flags", side.Flags) ("flags", side.Flags)
("leftside", side.LeftSide) //("leftside", side.LeftSide)
("rightside", side.RightSide) //("rightside", side.RightSide)
("index", side.Index) //("index", side.Index)
("attacheddecals", side.AttachedDecals) ("attacheddecals", side.AttachedDecals)
.EndObject(); .EndObject();
} }
@ -926,14 +957,11 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FDynamicColormap *&cm)
if (arc.isWriting()) if (arc.isWriting())
{ {
arc.WriteKey(key); arc.WriteKey(key);
arc.mWriter->StartObject(); arc.mWriter->StartArray();
arc.mWriter->Key("color");
arc.mWriter->Uint(cm->Color); arc.mWriter->Uint(cm->Color);
arc.mWriter->Key("fade");
arc.mWriter->Uint(cm->Fade); arc.mWriter->Uint(cm->Fade);
arc.mWriter->Key("desat");
arc.mWriter->Uint(cm->Desaturate); arc.mWriter->Uint(cm->Desaturate);
arc.mWriter->EndObject(); arc.mWriter->EndArray();
} }
else else
{ {
@ -942,9 +970,9 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FDynamicColormap *&cm)
{ {
if (val->IsObject()) if (val->IsObject())
{ {
const rapidjson::Value &colorval = (*val)["color"]; const rapidjson::Value &colorval = (*val)[0];
const rapidjson::Value &fadeval = (*val)["fade"]; const rapidjson::Value &fadeval = (*val)[1];
const rapidjson::Value &desatval = (*val)["desat"]; const rapidjson::Value &desatval = (*val)[2];
if (colorval.IsUint() && fadeval.IsUint() && desatval.IsUint()) if (colorval.IsUint() && fadeval.IsUint() && desatval.IsUint())
{ {
cm = GetSpecialLights(colorval.GetUint(), fadeval.GetUint(), desatval.GetUint()); cm = GetSpecialLights(colorval.GetUint(), fadeval.GetUint(), desatval.GetUint());
@ -980,10 +1008,10 @@ FSerializer &Serialize(FSerializer &arc, const char *key, sector_t &p)
("prevsec", p.prevsec) ("prevsec", p.prevsec)
("nextsec", p.nextsec) ("nextsec", p.nextsec)
.Array("planes", p.planes, 2) .Array("planes", p.planes, 2)
("heightsec", p.heightsec) //("heightsec", p.heightsec)
("bottommap", p.bottommap) //("bottommap", p.bottommap)
("midmap", p.midmap) //("midmap", p.midmap)
("topmap", p.topmap) //("topmap", p.topmap)
("damageamount", p.damageamount) ("damageamount", p.damageamount)
("damageinterval", p.damageinterval) ("damageinterval", p.damageinterval)
("leakydamage", p.leakydamage) ("leakydamage", p.leakydamage)
@ -1017,34 +1045,37 @@ FSerializer &Serialize(FSerializer &arc, const char *key, subsector_t *&ss)
{ {
BYTE by; BYTE by;
if (arc.isWriting() && hasglnodes) if (arc.isWriting())
{ {
TArray<char> encoded((numsubsectors + 5) / 6); if (hasglnodes)
int p = 0;
for (int i = 0; i < numsubsectors; i += 6)
{ {
by = 0; TArray<char> encoded((numsubsectors + 5) / 6);
for (int j = 0; j < 6; j++) int p = 0;
for (int i = 0; i < numsubsectors; i += 6)
{ {
if (i + j < numsubsectors && (subsectors[i + j].flags & SSECF_DRAWN)) by = 0;
for (int j = 0; j < 6; j++)
{ {
by |= (1 << j); if (i + j < numsubsectors && (subsectors[i + j].flags & SSECF_DRAWN))
{
by |= (1 << j);
}
} }
if (by < 10) by += '0';
else if (by < 36) by += 'A' - 10;
else if (by < 62) by += 'a' - 36;
else if (by == 62) by = '-';
else if (by == 63) by = '+';
encoded[p++] = by;
} }
if (by < 10) by += '0'; arc.mWriter->Key(key);
else if (by < 36) by += 'A' - 10; arc.mWriter->StartArray();
else if (by < 62) by += 'a' - 36; arc.mWriter->Int(numvertexes);
else if (by == 62) by = '-'; arc.mWriter->Int(numsubsectors);
else if (by == 63) by = '+'; arc.mWriter->Int(numnodes);
encoded[p++] = by; arc.mWriter->String(&encoded[0], (numsubsectors + 5) / 6);
arc.mWriter->EndArray();
} }
arc.mWriter->Key(key);
arc.mWriter->StartArray();
arc.mWriter->Int(numvertexes);
arc.mWriter->Int(numsubsectors);
arc.mWriter->Int(numnodes);
arc.mWriter->String(&encoded[0], (numsubsectors + 5) / 6);
arc.mWriter->EndArray();
} }
else else
{ {
@ -1403,154 +1434,157 @@ void SerializeObjects(FSerializer &arc)
// //
//========================================================================== //==========================================================================
#define A(a,b) ((a), (b), def->b)
void AActor::Serialize(FSerializer &arc) void AActor::Serialize(FSerializer &arc)
{ {
int damage = 0; // just a placeholder until the insanity surrounding the damage property can be fixed int damage = 0; // just a placeholder until the insanity surrounding the damage property can be fixed
AActor *def = GetDefault();
Super::Serialize(arc); Super::Serialize(arc);
arc arc
.Sprite("sprite", sprite) .Sprite("sprite", sprite)
("pos", __Pos) A("pos", __Pos)
("angles", Angles) A("angles", Angles)
("frame", frame) A("frame", frame)
("scale", Scale) A("scale", Scale)
("renderstyle", RenderStyle) A("renderstyle", RenderStyle)
("renderflags", renderflags) A("renderflags", renderflags)
("picnum", picnum) A("picnum", picnum)
("floorpic", floorpic) A("floorpic", floorpic)
("ceilingpic", ceilingpic) A("ceilingpic", ceilingpic)
("tidtohate", TIDtoHate) A("tidtohate", TIDtoHate)
("lastlookpn", LastLookPlayerNumber) A("lastlookpn", LastLookPlayerNumber)
("lastlookactor", LastLookActor) ("lastlookactor", LastLookActor)
("effects", effects) A("effects", effects)
("alpha", Alpha) A("alpha", Alpha)
("fillcolor", fillcolor) A("fillcolor", fillcolor)
("sector", Sector) A("sector", Sector)
("floorz", floorz) A("floorz", floorz)
("ceilingz", ceilingz) A("ceilingz", ceilingz)
("dropoffz", dropoffz) A("dropoffz", dropoffz)
("floorsector", floorsector) A("floorsector", floorsector)
("ceilingsector", ceilingsector) A("ceilingsector", ceilingsector)
("radius", radius) A("radius", radius)
("height", Height) A("height", Height)
("ppassheight", projectilepassheight) A("ppassheight", projectilepassheight)
("vel", Vel) A("vel", Vel)
("tics", tics) A("tics", tics)
("state", state) ("state", state)
("damage", damage) ("damage", damage)
.Terrain("floorterrain", floorterrain) .Terrain("floorterrain", floorterrain)
("projectilekickback", projectileKickback) A("projectilekickback", projectileKickback)
("flags", flags) A("flags", flags)
("flags2", flags2) A("flags2", flags2)
("flags3", flags3) A("flags3", flags3)
("flags4", flags4) A("flags4", flags4)
("flags5", flags5) A("flags5", flags5)
("flags6", flags6) A("flags6", flags6)
("flags7", flags7) A("flags7", flags7)
("weaponspecial", weaponspecial) A("weaponspecial", weaponspecial)
("special1", special1) A("special1", special1)
("special2", special2) A("special2", special2)
("specialf1", specialf1) A("specialf1", specialf1)
("specialf2", specialf2) A("specialf2", specialf2)
("health", health) A("health", health)
("movedir", movedir) A("movedir", movedir)
("visdir", visdir) A("visdir", visdir)
("movecount", movecount) A("movecount", movecount)
("strafecount", strafecount) A("strafecount", strafecount)
("target", target) ("target", target)
("lastenemy", lastenemy) ("lastenemy", lastenemy)
("lastheard", LastHeard) ("lastheard", LastHeard)
("reactiontime", reactiontime) A("reactiontime", reactiontime)
("threshold", threshold) A("threshold", threshold)
("player", player) A("player", player)
("spawnpoint", SpawnPoint) A("spawnpoint", SpawnPoint)
("spawnangle", SpawnAngle) A("spawnangle", SpawnAngle)
("starthealth", StartHealth) A("starthealth", StartHealth)
("skillrespawncount", skillrespawncount) A("skillrespawncount", skillrespawncount)
("tracer", tracer) ("tracer", tracer)
("floorclip", Floorclip) A("floorclip", Floorclip)
("tid", tid) A("tid", tid)
("special", special) A("special", special)
.Args("args", args, special) .Args("args", args, special)
("accuracy", accuracy) A("accuracy", accuracy)
("stamina", stamina) A("stamina", stamina)
("goal", goal) ("goal", goal)
("waterlevel", waterlevel) A("waterlevel", waterlevel)
("minmissilechance", MinMissileChance) A("minmissilechance", MinMissileChance)
("spawnflags", SpawnFlags) A("spawnflags", SpawnFlags)
("inventory", Inventory) ("inventory", Inventory)
("inventoryid", InventoryID) A("inventoryid", InventoryID)
("floatbobphase", FloatBobPhase) A("floatbobphase", FloatBobPhase)
("translation", Translation) A("translation", Translation)
("seesound", SeeSound) A("seesound", SeeSound)
("attacksound", AttackSound) A("attacksound", AttackSound)
("paimsound", PainSound) A("paimsound", PainSound)
("deathsound", DeathSound) A("deathsound", DeathSound)
("activesound", ActiveSound) A("activesound", ActiveSound)
("usesound", UseSound) A("usesound", UseSound)
("bouncesound", BounceSound) A("bouncesound", BounceSound)
("wallbouncesound", WallBounceSound) A("wallbouncesound", WallBounceSound)
("crushpainsound", CrushPainSound) A("crushpainsound", CrushPainSound)
("speed", Speed) A("speed", Speed)
("floatspeed", FloatSpeed) A("floatspeed", FloatSpeed)
("mass", Mass) A("mass", Mass)
("painchance", PainChance) A("painchance", PainChance)
("spawnstate", SpawnState) A("spawnstate", SpawnState)
("seestate", SeeState) A("seestate", SeeState)
("meleestate", MeleeState) A("meleestate", MeleeState)
("missilestate", MissileState) A("missilestate", MissileState)
("maxdropoffheight", MaxDropOffHeight) A("maxdropoffheight", MaxDropOffHeight)
("maxstepheight", MaxStepHeight) A("maxstepheight", MaxStepHeight)
("bounceflags", BounceFlags) A("bounceflags", BounceFlags)
("bouncefactor", bouncefactor) A("bouncefactor", bouncefactor)
("wallbouncefactor", wallbouncefactor) A("wallbouncefactor", wallbouncefactor)
("bouncecount", bouncecount) A("bouncecount", bouncecount)
("maxtargetrange", maxtargetrange) A("maxtargetrange", maxtargetrange)
("meleethreshold", meleethreshold) A("meleethreshold", meleethreshold)
("meleerange", meleerange) A("meleerange", meleerange)
("damagetype", DamageType) A("damagetype", DamageType)
("damagetypereceived", DamageTypeReceived) A("damagetypereceived", DamageTypeReceived)
("paintype", PainType) A("paintype", PainType)
("deathtype", DeathType) A("deathtype", DeathType)
("gravity", Gravity) A("gravity", Gravity)
("fastchasestrafecount", FastChaseStrafeCount) A("fastchasestrafecount", FastChaseStrafeCount)
("master", master) ("master", master)
("smokecounter", smokecounter) A("smokecounter", smokecounter)
("blockingmobj", BlockingMobj) ("blockingmobj", BlockingMobj)
("blockingline", BlockingLine) A("blockingline", BlockingLine)
("visibletoteam", VisibleToTeam) A("visibletoteam", VisibleToTeam)
("pushfactor", pushfactor) A("pushfactor", pushfactor)
("species", Species) A("species", Species)
("score", Score) A("score", Score)
("designatedteam", DesignatedTeam) A("designatedteam", DesignatedTeam)
("lastpush", lastpush) A("lastpush", lastpush)
("lastbump", lastbump) A("lastbump", lastbump)
("painthreshold", PainThreshold) A("painthreshold", PainThreshold)
("damagefactor", DamageFactor) A("damagefactor", DamageFactor)
("damagemultiply", DamageMultiply) A("damagemultiply", DamageMultiply)
("waveindexxy", WeaveIndexXY) A("waveindexxy", WeaveIndexXY)
("weaveindexz", WeaveIndexZ) A("weaveindexz", WeaveIndexZ)
("pdmgreceived", PoisonDamageReceived) A("pdmgreceived", PoisonDamageReceived)
("pdurreceived", PoisonDurationReceived) A("pdurreceived", PoisonDurationReceived)
("ppreceived", PoisonPeriodReceived) A("ppreceived", PoisonPeriodReceived)
("poisoner", Poisoner) A("poisoner", Poisoner)
("posiondamage", PoisonDamage) A("posiondamage", PoisonDamage)
("poisonduration", PoisonDuration) A("poisonduration", PoisonDuration)
("poisonperiod", PoisonPeriod) A("poisonperiod", PoisonPeriod)
("poisondamagetype", PoisonDamageType) A("poisondamagetype", PoisonDamageType)
("poisondmgtypereceived", PoisonDamageTypeReceived) A("poisondmgtypereceived", PoisonDamageTypeReceived)
("conversationroot", ConversationRoot) A("conversationroot", ConversationRoot)
("conversation", Conversation) A("conversation", Conversation)
("friendplayer", FriendPlayer) A("friendplayer", FriendPlayer)
("telefogsourcetype", TeleFogSourceType) A("telefogsourcetype", TeleFogSourceType)
("telefogdesttype", TeleFogDestType) A("telefogdesttype", TeleFogDestType)
("ripperlevel", RipperLevel) A("ripperlevel", RipperLevel)
("riplevelmin", RipLevelMin) A("riplevelmin", RipLevelMin)
("riplevelmax", RipLevelMax) A("riplevelmax", RipLevelMax)
("devthreshold", DefThreshold) A("devthreshold", DefThreshold)
("spriteangle", SpriteAngle) A("spriteangle", SpriteAngle)
("spriterotation", SpriteRotation) A("spriterotation", SpriteRotation)
("alternative", alternative) ("alternative", alternative)
("tag", Tag); ("tag", Tag);

View file

@ -124,6 +124,7 @@ glsegextra_t* glsegextras;
int numsectors; int numsectors;
sector_t* sectors; sector_t* sectors;
TArray<sector_t> loadsectors;
int numsubsectors; int numsubsectors;
subsector_t* subsectors; subsector_t* subsectors;
@ -133,9 +134,11 @@ node_t* nodes;
int numlines; int numlines;
line_t* lines; line_t* lines;
TArray<line_t> loadlines;
int numsides; int numsides;
side_t* sides; side_t* sides;
TArray<side_t> loadsides;
TArray<zone_t> Zones; TArray<zone_t> Zones;
@ -4195,6 +4198,13 @@ void P_SetupLevel (const char *lumpname, int position)
MapThingsUserDataIndex.Clear(); MapThingsUserDataIndex.Clear();
MapThingsUserData.Clear(); MapThingsUserData.Clear();
loadsectors.Resize(numsectors);
memcpy(&loadsectors[0], sectors, numsectors * sizeof(sector_t));
loadlines.Resize(numlines);
memcpy(&loadlines[0], lines, numlines * sizeof(line_t));
loadsides.Resize(numsides);
memcpy(&loadsides[0], sides, numsides * sizeof(side_t));
if (glsegextras != NULL) if (glsegextras != NULL)
{ {
delete[] glsegextras; delete[] glsegextras;