- fixed incomplete hudmessage serialization.

- fixed a few errors in the ACS module serializer.
- reordered a few things to how they were in the old code.
- optimized serialization of the level.Scrolls array to happen within the sector. This is to allow skipping 0-entries which normally constitute the vast majority of them.
This commit is contained in:
Christoph Oelckers 2016-09-20 13:21:41 +02:00
parent cf1e6d5275
commit f3e8c7c241
6 changed files with 102 additions and 70 deletions

View file

@ -182,6 +182,10 @@ void DHUDMessage::Serialize(FSerializer &arc)
("tics", Tics) ("tics", Tics)
("state", State) ("state", State)
.Enum("textcolor", TextColor) .Enum("textcolor", TextColor)
("sbarid", SBarID)
("sourcetext", SourceText)
("font", Font)
("next", Next)
("hudwidth", HUDWidth) ("hudwidth", HUDWidth)
("hudheight", HUDHeight) ("hudheight", HUDHeight)
("nowrap", NoWrap) ("nowrap", NoWrap)

View file

@ -71,7 +71,6 @@ CCMD(writejson)
FSerializer arc; FSerializer arc;
arc.OpenWriter(); arc.OpenWriter();
arc.BeginObject(nullptr); arc.BeginObject(nullptr);
DThinker::SerializeThinkers(arc, false);
G_SerializeLevel(arc, false); G_SerializeLevel(arc, false);
arc.WriteObjects(); arc.WriteObjects();
arc.EndObject(); arc.EndObject();

View file

@ -1646,7 +1646,7 @@ void FBehavior::StaticSerializeModuleStates (FSerializer &arc)
if (arc.BeginArray("modules")) if (arc.BeginArray("modules"))
{ {
FBehavior *module = StaticModules[modnum]; FBehavior *module = StaticModules[modnum];
const char *modname; const char *modname = module->ModuleName;
int ModSize = module->GetDataSize(); int ModSize = module->GetDataSize();
if (arc.BeginObject(nullptr)) if (arc.BeginObject(nullptr))
@ -1693,50 +1693,54 @@ void FBehavior::SerializeVarSet (FSerializer &arc, SDWORD *vars, int max)
SDWORD count; SDWORD count;
SDWORD first, last; SDWORD first, last;
if (arc.isWriting ()) if (arc.BeginObject(nullptr))
{ {
// Find first non-zero variable if (arc.isWriting())
for (first = 0; first < max; ++first)
{ {
if (vars[first] != 0) // Find first non-zero variable
for (first = 0; first < max; ++first)
{ {
break; if (vars[first] != 0)
{
break;
}
}
// Find last non-zero variable
for (last = max - 1; last >= first; --last)
{
if (vars[last] != 0)
{
break;
}
}
if (last < first)
{ // no non-zero variables
count = 0;
arc("count", count);
}
else
{
count = last - first + 1;
arc("count", count);
arc("first", first);
arc.Array("values", &vars[first], count);
} }
} }
else
// Find last non-zero variable
for (last = max - 1; last >= first; --last)
{ {
if (vars[last] != 0) memset(vars, 0, max * sizeof(*vars));
{
break;
}
}
if (last < first)
{ // no non-zero variables
count = 0;
arc("count", count); arc("count", count);
return;
}
count = last - first + 1; if (count != 0)
arc("count", count); {
arc("first", first); arc("first", first);
arc.Array("values", &vars[first], count); if (first + count > max) count = max - first;
} arc.Array("values", &vars[first], count);
else }
{
memset (vars, 0, max*sizeof(*vars));
arc("count", count);
if (count == 0)
{
return;
} }
arc("first", first); arc.EndObject();
if (first + count > max) count = max - first;
arc.Array("values", &vars[first], count);
} }
} }
@ -2923,6 +2927,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, SavingRunningscript &r
void DACSThinker::Serialize(FSerializer &arc) void DACSThinker::Serialize(FSerializer &arc)
{ {
Super::Serialize(arc);
arc("scripts", Scripts); arc("scripts", Scripts);
if (arc.isWriting()) if (arc.isWriting())
@ -3007,29 +3012,6 @@ END_POINTERS
// //
//========================================================================== //==========================================================================
template<> FSerializer &Serialize(FSerializer &arc, const char *key, FFont *&font, FFont **def)
{
if (arc.isWriting())
{
const char *n = font->GetName();
return arc.StringPtr(key, n);
}
else
{
const char *n;
arc.StringPtr(key, n);
font = V_GetFont(n);
if (font == NULL)
{
Printf("Could not load font %s\n", n);
font = SmallFont;
}
return arc;
}
}
void DLevelScript::Serialize(FSerializer &arc) void DLevelScript::Serialize(FSerializer &arc)
{ {
Super::Serialize(arc); Super::Serialize(arc);

View file

@ -527,13 +527,17 @@ FSerializer &Serialize(FSerializer &arc, const char *key, secplane_t &p, secplan
FSerializer &Serialize(FSerializer &arc, const char *key, sector_t &p, sector_t *def) FSerializer &Serialize(FSerializer &arc, const char *key, sector_t &p, sector_t *def)
{ {
// save the Scroll data here because it's a lot easier to handle a default.
// Just writing out the full array can massively inflate the archive for no gain.
DVector2 scroll = { 0,0 }, nul = { 0,0 };
if (arc.isWriting() && level.Scrolls.Size() > 0) scroll = level.Scrolls[p.sectornum];
if (arc.BeginObject(key)) if (arc.BeginObject(key))
{ {
arc("floorplane", p.floorplane, def->floorplane) arc("floorplane", p.floorplane, def->floorplane)
("ceilingplane", p.ceilingplane, def->ceilingplane) ("ceilingplane", p.ceilingplane, def->ceilingplane)
("lightlevel", p.lightlevel, def->lightlevel) ("lightlevel", p.lightlevel, def->lightlevel)
("special", p.special, def->special) ("special", p.special, def->special)
("soundtraversed", p.soundtraversed, def->soundtraversed)
("seqtype", p.seqType, def->seqType) ("seqtype", p.seqType, def->seqType)
("seqname", p.SeqName, def->SeqName) ("seqname", p.SeqName, def->SeqName)
("friction", p.friction, def->friction) ("friction", p.friction, def->friction)
@ -572,7 +576,17 @@ FSerializer &Serialize(FSerializer &arc, const char *key, sector_t &p, sector_t
("colormap", p.ColorMap, def->ColorMap) ("colormap", p.ColorMap, def->ColorMap)
.Terrain("floorterrain", p.terrainnum[0], &def->terrainnum[0]) .Terrain("floorterrain", p.terrainnum[0], &def->terrainnum[0])
.Terrain("ceilingterrain", p.terrainnum[1], &def->terrainnum[1]) .Terrain("ceilingterrain", p.terrainnum[1], &def->terrainnum[1])
("scrolls", scroll, nul)
.EndObject(); .EndObject();
if (!scroll.isZero())
{
if (level.Scrolls.Size() == 0)
{
level.Scrolls.Resize(numsectors);
memset(&level.Scrolls[0], 0, sizeof(level.Scrolls[0])*level.Scrolls.Size());
}
}
} }
return arc; return arc;
} }
@ -837,8 +851,7 @@ void G_SerializeLevel(FSerializer &arc, bool hubload)
("level.maptime", level.maptime) ("level.maptime", level.maptime)
("level.totaltime", i) ("level.totaltime", i)
("level.skytexture1", level.skytexture1) ("level.skytexture1", level.skytexture1)
("level.skytexture2", level.skytexture2) ("level.skytexture2", level.skytexture2);
("level.scrolls", level.Scrolls);
// Hub transitions must keep the current total time // Hub transitions must keep the current total time
if (!hubload) if (!hubload)
@ -852,23 +865,26 @@ void G_SerializeLevel(FSerializer &arc, bool hubload)
interpolator.ClearInterpolations(); interpolator.ClearInterpolations();
} }
G_AirControlChanged(); G_AirControlChanged();
// fixme: This needs to ensure it reads from the correct place. Should be one once there's enough of this code converted to JSON // fixme: This needs to ensure it reads from the correct place. Should be one once there's enough of this code converted to JSON
AM_SerializeMarkers(arc);
FBehavior::StaticSerializeModuleStates(arc); FBehavior::StaticSerializeModuleStates(arc);
// The order here is important: First world state, then portal state, then thinkers, and last polyobjects.
arc.Array("linedefs", lines, &loadlines[0], numlines); arc.Array("linedefs", lines, &loadlines[0], numlines);
arc.Array("sidedefs", sides, &loadsides[0], numsides); arc.Array("sidedefs", sides, &loadsides[0], numsides);
arc.Array("sectors", sectors, &loadsectors[0], numsectors); arc.Array("sectors", sectors, &loadsectors[0], numsectors);
arc.Array("polyobjs", polyobjs, po_NumPolyobjs);
arc("subsectors", subsectors);
StatusBar->SerializeMessages(arc);
arc("zones", Zones); arc("zones", Zones);
arc("lineportals", linePortals); arc("lineportals", linePortals);
arc("sectorportals", sectorPortals); arc("sectorportals", sectorPortals);
if (arc.isReading()) P_CollectLinkedPortals(); if (arc.isReading()) P_CollectLinkedPortals();
DThinker::SerializeThinkers(arc, !hubload);
arc.Array("polyobjs", polyobjs, po_NumPolyobjs);
arc("subsectors", subsectors);
StatusBar->SerializeMessages(arc);
AM_SerializeMarkers(arc);
} }

View file

@ -29,6 +29,7 @@
#include "r_data/r_interpolate.h" #include "r_data/r_interpolate.h"
#include "g_shared/a_sharedglobal.h" #include "g_shared/a_sharedglobal.h"
#include "po_man.h" #include "po_man.h"
#include "v_font.h"
char nulspace[1024 * 1024 * 4]; char nulspace[1024 * 1024 * 4];
@ -211,6 +212,7 @@ void FSerializer::WriteKey(const char *key)
{ {
if (isWriting() && w->inObject()) if (isWriting() && w->inObject())
{ {
assert(key != nullptr);
if (key == nullptr) if (key == nullptr)
{ {
I_Error("missing element name"); I_Error("missing element name");
@ -426,7 +428,6 @@ FSerializer &FSerializer::ScriptNum(const char *key, int &num)
{ {
w->mWriter.Int(num); w->mWriter.Int(num);
} }
w->mWriter.EndArray();
} }
else else
{ {
@ -1435,3 +1436,32 @@ template<> FSerializer &Serialize(FSerializer &arc, const char *key, char *&pstr
} }
return arc; return arc;
} }
//==========================================================================
//
//
//
//==========================================================================
template<> FSerializer &Serialize(FSerializer &arc, const char *key, FFont *&font, FFont **def)
{
if (arc.isWriting())
{
const char *n = font->GetName();
return arc.StringPtr(key, n);
}
else
{
const char *n;
arc.StringPtr(key, n);
font = V_GetFont(n);
if (font == NULL)
{
Printf("Could not load font %s\n", n);
font = SmallFont;
}
return arc;
}
}

View file

@ -189,6 +189,7 @@ template<> FSerializer &Serialize(FSerializer &arc, const char *key, FStrifeDial
template<> FSerializer &Serialize(FSerializer &arc, const char *key, FString *&pstr, FString **def); template<> FSerializer &Serialize(FSerializer &arc, const char *key, FString *&pstr, FString **def);
template<> FSerializer &Serialize(FSerializer &arc, const char *key, FDoorAnimation *&pstr, FDoorAnimation **def); template<> FSerializer &Serialize(FSerializer &arc, const char *key, FDoorAnimation *&pstr, FDoorAnimation **def);
template<> FSerializer &Serialize(FSerializer &arc, const char *key, char *&pstr, char **def); template<> FSerializer &Serialize(FSerializer &arc, const char *key, char *&pstr, char **def);
template<> FSerializer &Serialize(FSerializer &arc, const char *key, FFont *&font, FFont **def);
inline FSerializer &Serialize(FSerializer &arc, const char *key, DVector3 &p, DVector3 *def) inline FSerializer &Serialize(FSerializer &arc, const char *key, DVector3 &p, DVector3 *def)