mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-27 22:42:57 +00:00
- 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:
parent
cf1e6d5275
commit
f3e8c7c241
6 changed files with 102 additions and 70 deletions
|
@ -182,6 +182,10 @@ void DHUDMessage::Serialize(FSerializer &arc)
|
|||
("tics", Tics)
|
||||
("state", State)
|
||||
.Enum("textcolor", TextColor)
|
||||
("sbarid", SBarID)
|
||||
("sourcetext", SourceText)
|
||||
("font", Font)
|
||||
("next", Next)
|
||||
("hudwidth", HUDWidth)
|
||||
("hudheight", HUDHeight)
|
||||
("nowrap", NoWrap)
|
||||
|
|
|
@ -71,7 +71,6 @@ CCMD(writejson)
|
|||
FSerializer arc;
|
||||
arc.OpenWriter();
|
||||
arc.BeginObject(nullptr);
|
||||
DThinker::SerializeThinkers(arc, false);
|
||||
G_SerializeLevel(arc, false);
|
||||
arc.WriteObjects();
|
||||
arc.EndObject();
|
||||
|
|
100
src/p_acs.cpp
100
src/p_acs.cpp
|
@ -1646,7 +1646,7 @@ void FBehavior::StaticSerializeModuleStates (FSerializer &arc)
|
|||
if (arc.BeginArray("modules"))
|
||||
{
|
||||
FBehavior *module = StaticModules[modnum];
|
||||
const char *modname;
|
||||
const char *modname = module->ModuleName;
|
||||
int ModSize = module->GetDataSize();
|
||||
|
||||
if (arc.BeginObject(nullptr))
|
||||
|
@ -1693,50 +1693,54 @@ void FBehavior::SerializeVarSet (FSerializer &arc, SDWORD *vars, int max)
|
|||
SDWORD count;
|
||||
SDWORD first, last;
|
||||
|
||||
if (arc.isWriting ())
|
||||
if (arc.BeginObject(nullptr))
|
||||
{
|
||||
// Find first non-zero variable
|
||||
for (first = 0; first < max; ++first)
|
||||
if (arc.isWriting())
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// Find last non-zero variable
|
||||
for (last = max - 1; last >= first; --last)
|
||||
else
|
||||
{
|
||||
if (vars[last] != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (last < first)
|
||||
{ // no non-zero variables
|
||||
count = 0;
|
||||
memset(vars, 0, max * sizeof(*vars));
|
||||
arc("count", count);
|
||||
return;
|
||||
}
|
||||
|
||||
count = last - first + 1;
|
||||
arc("count", count);
|
||||
arc("first", first);
|
||||
arc.Array("values", &vars[first], count);
|
||||
}
|
||||
else
|
||||
{
|
||||
memset (vars, 0, max*sizeof(*vars));
|
||||
arc("count", count);
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
return;
|
||||
if (count != 0)
|
||||
{
|
||||
arc("first", first);
|
||||
if (first + count > max) count = max - first;
|
||||
arc.Array("values", &vars[first], count);
|
||||
}
|
||||
}
|
||||
arc("first", first);
|
||||
if (first + count > max) count = max - first;
|
||||
arc.Array("values", &vars[first], count);
|
||||
arc.EndObject();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2923,6 +2927,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, SavingRunningscript &r
|
|||
|
||||
void DACSThinker::Serialize(FSerializer &arc)
|
||||
{
|
||||
Super::Serialize(arc);
|
||||
arc("scripts", Scripts);
|
||||
|
||||
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)
|
||||
{
|
||||
Super::Serialize(arc);
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
// 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))
|
||||
{
|
||||
arc("floorplane", p.floorplane, def->floorplane)
|
||||
("ceilingplane", p.ceilingplane, def->ceilingplane)
|
||||
("lightlevel", p.lightlevel, def->lightlevel)
|
||||
("special", p.special, def->special)
|
||||
("soundtraversed", p.soundtraversed, def->soundtraversed)
|
||||
("seqtype", p.seqType, def->seqType)
|
||||
("seqname", p.SeqName, def->SeqName)
|
||||
("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)
|
||||
.Terrain("floorterrain", p.terrainnum[0], &def->terrainnum[0])
|
||||
.Terrain("ceilingterrain", p.terrainnum[1], &def->terrainnum[1])
|
||||
("scrolls", scroll, nul)
|
||||
.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;
|
||||
}
|
||||
|
@ -837,8 +851,7 @@ void G_SerializeLevel(FSerializer &arc, bool hubload)
|
|||
("level.maptime", level.maptime)
|
||||
("level.totaltime", i)
|
||||
("level.skytexture1", level.skytexture1)
|
||||
("level.skytexture2", level.skytexture2)
|
||||
("level.scrolls", level.Scrolls);
|
||||
("level.skytexture2", level.skytexture2);
|
||||
|
||||
// Hub transitions must keep the current total time
|
||||
if (!hubload)
|
||||
|
@ -852,23 +865,26 @@ void G_SerializeLevel(FSerializer &arc, bool hubload)
|
|||
interpolator.ClearInterpolations();
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
AM_SerializeMarkers(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("sidedefs", sides, &loadsides[0], numsides);
|
||||
arc.Array("sectors", sectors, &loadsectors[0], numsectors);
|
||||
arc.Array("polyobjs", polyobjs, po_NumPolyobjs);
|
||||
arc("subsectors", subsectors);
|
||||
StatusBar->SerializeMessages(arc);
|
||||
arc("zones", Zones);
|
||||
arc("lineportals", linePortals);
|
||||
arc("sectorportals", sectorPortals);
|
||||
|
||||
if (arc.isReading()) P_CollectLinkedPortals();
|
||||
DThinker::SerializeThinkers(arc, !hubload);
|
||||
arc.Array("polyobjs", polyobjs, po_NumPolyobjs);
|
||||
arc("subsectors", subsectors);
|
||||
StatusBar->SerializeMessages(arc);
|
||||
AM_SerializeMarkers(arc);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "r_data/r_interpolate.h"
|
||||
#include "g_shared/a_sharedglobal.h"
|
||||
#include "po_man.h"
|
||||
#include "v_font.h"
|
||||
|
||||
char nulspace[1024 * 1024 * 4];
|
||||
|
||||
|
@ -211,6 +212,7 @@ void FSerializer::WriteKey(const char *key)
|
|||
{
|
||||
if (isWriting() && w->inObject())
|
||||
{
|
||||
assert(key != nullptr);
|
||||
if (key == nullptr)
|
||||
{
|
||||
I_Error("missing element name");
|
||||
|
@ -426,7 +428,6 @@ FSerializer &FSerializer::ScriptNum(const char *key, int &num)
|
|||
{
|
||||
w->mWriter.Int(num);
|
||||
}
|
||||
w->mWriter.EndArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1434,4 +1435,33 @@ template<> FSerializer &Serialize(FSerializer &arc, const char *key, char *&pstr
|
|||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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, FDoorAnimation *&pstr, FDoorAnimation **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)
|
||||
|
|
Loading…
Reference in a new issue