2016-03-01 15:47:10 +00:00
|
|
|
/*
|
|
|
|
** p_saveg.cpp
|
|
|
|
** Code for serializing the world state in an archive
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
2016-09-19 08:34:54 +00:00
|
|
|
** Copyright 1998-2016 Randy Heit
|
|
|
|
** Copyright 2005-2016 Christoph Oelckers
|
2016-03-01 15:47:10 +00:00
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2019-01-31 18:38:04 +00:00
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
#include "p_local.h"
|
|
|
|
#include "p_spec.h"
|
|
|
|
|
|
|
|
// State.
|
|
|
|
#include "d_player.h"
|
|
|
|
#include "p_saveg.h"
|
|
|
|
#include "s_sndseq.h"
|
|
|
|
#include "a_sharedglobal.h"
|
|
|
|
#include "r_data/r_interpolate.h"
|
|
|
|
#include "po_man.h"
|
|
|
|
#include "p_setup.h"
|
|
|
|
#include "p_lnspec.h"
|
|
|
|
#include "p_acs.h"
|
|
|
|
#include "p_terrain.h"
|
2016-09-19 08:34:54 +00:00
|
|
|
#include "am_map.h"
|
|
|
|
#include "sbar.h"
|
|
|
|
#include "r_utility.h"
|
|
|
|
#include "r_sky.h"
|
|
|
|
#include "r_renderer.h"
|
|
|
|
#include "serializer.h"
|
2017-01-08 17:45:30 +00:00
|
|
|
#include "g_levellocals.h"
|
2017-01-23 21:05:51 +00:00
|
|
|
#include "events.h"
|
2018-10-31 20:40:08 +00:00
|
|
|
#include "p_destructible.h"
|
2019-01-29 03:44:44 +00:00
|
|
|
#include "r_sky.h"
|
2019-01-05 08:40:03 +00:00
|
|
|
#include "fragglescript/t_script.h"
|
2016-09-19 08:34:54 +00:00
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
FSerializer &Serialize(FSerializer &arc, const char *key, line_t &line, line_t *def)
|
|
|
|
{
|
|
|
|
if (arc.BeginObject(key))
|
|
|
|
{
|
|
|
|
arc("flags", line.flags, def->flags)
|
|
|
|
("activation", line.activation, def->activation)
|
|
|
|
("special", line.special, def->special)
|
|
|
|
("alpha", line.alpha, def->alpha)
|
|
|
|
.Args("args", line.args, def->args, line.special)
|
|
|
|
("portalindex", line.portalindex, def->portalindex)
|
2018-10-16 11:02:14 +00:00
|
|
|
("locknumber", line.locknumber, def->locknumber)
|
2018-10-31 20:40:08 +00:00
|
|
|
("health", line.health, def->health)
|
2016-09-19 08:34:54 +00:00
|
|
|
// Unless the map loader is changed the sidedef references will not change between map loads so there's no need to save them.
|
|
|
|
//.Array("sides", line.sidedef, 2)
|
|
|
|
.EndObject();
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2016-09-19 08:34:54 +00:00
|
|
|
return arc;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-09-19 08:34:54 +00:00
|
|
|
FSerializer &Serialize(FSerializer &arc, const char *key, side_t::part &part, side_t::part *def)
|
|
|
|
{
|
|
|
|
if (arc.canSkip() && def != nullptr && !memcmp(&part, def, sizeof(part)))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-09-19 08:34:54 +00:00
|
|
|
return arc;
|
|
|
|
}
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-09-19 08:34:54 +00:00
|
|
|
if (arc.BeginObject(key))
|
|
|
|
{
|
|
|
|
arc("xoffset", part.xOffset, def->xOffset)
|
|
|
|
("yoffset", part.yOffset, def->yOffset)
|
|
|
|
("xscale", part.xScale, def->xScale)
|
|
|
|
("yscale", part.yScale, def->yScale)
|
|
|
|
("texture", part.texture, def->texture)
|
|
|
|
("interpolation", part.interpolation)
|
2018-11-11 15:04:05 +00:00
|
|
|
("flags", part.flags, def->flags)
|
|
|
|
("color1", part.SpecialColors[0], def->SpecialColors[0])
|
|
|
|
("color2", part.SpecialColors[1], def->SpecialColors[1])
|
2018-12-21 00:03:52 +00:00
|
|
|
("addcolor", part.AdditiveColor, def->AdditiveColor)
|
2016-09-19 08:34:54 +00:00
|
|
|
.EndObject();
|
|
|
|
}
|
|
|
|
return arc;
|
|
|
|
}
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-09-19 08:34:54 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
FSerializer &Serialize(FSerializer &arc, const char *key, side_t &side, side_t *def)
|
|
|
|
{
|
|
|
|
if (arc.BeginObject(key))
|
|
|
|
{
|
|
|
|
arc.Array("textures", side.textures, def->textures, 3, true)
|
|
|
|
("light", side.Light, def->Light)
|
|
|
|
("flags", side.Flags, def->Flags)
|
|
|
|
// These also remain identical across map loads
|
|
|
|
//("leftside", side.LeftSide)
|
|
|
|
//("rightside", side.RightSide)
|
|
|
|
//("index", side.Index)
|
|
|
|
("attacheddecals", side.AttachedDecals)
|
|
|
|
.EndObject();
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2016-09-19 08:34:54 +00:00
|
|
|
return arc;
|
|
|
|
}
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-09-19 08:34:54 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-09-19 08:34:54 +00:00
|
|
|
FSerializer &Serialize(FSerializer &arc, const char *key, FLinkedSector &ls, FLinkedSector *def)
|
|
|
|
{
|
|
|
|
if (arc.BeginObject(key))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-09-19 08:34:54 +00:00
|
|
|
arc("sector", ls.Sector)
|
|
|
|
("type", ls.Type)
|
|
|
|
.EndObject();
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2016-09-19 08:34:54 +00:00
|
|
|
return arc;
|
|
|
|
}
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2017-03-15 15:47:42 +00:00
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// Save a sector portal for savegames.
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
FSerializer &Serialize(FSerializer &arc, const char *key, FColormap &port, FColormap *def)
|
|
|
|
{
|
|
|
|
if (arc.canSkip() && def != nullptr && port == *def)
|
|
|
|
{
|
|
|
|
return arc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arc.BeginObject(key))
|
|
|
|
{
|
|
|
|
arc("lightcolor", port.LightColor)
|
|
|
|
("fadecolor", port.FadeColor)
|
|
|
|
("desaturation", port.Desaturation)
|
|
|
|
("fogdensity", port.FogDensity)
|
|
|
|
.EndObject();
|
|
|
|
}
|
|
|
|
return arc;
|
|
|
|
}
|
|
|
|
|
2016-09-19 08:34:54 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
FSerializer &Serialize(FSerializer &arc, const char *key, sector_t::splane &p, sector_t::splane *def)
|
|
|
|
{
|
|
|
|
if (arc.canSkip() && def != nullptr && !memcmp(&p, def, sizeof(p)))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-09-19 08:34:54 +00:00
|
|
|
return arc;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
2016-09-19 08:34:54 +00:00
|
|
|
if (arc.BeginObject(key))
|
|
|
|
{
|
|
|
|
arc("xoffs", p.xform.xOffs, def->xform.xOffs)
|
|
|
|
("yoffs", p.xform.yOffs, def->xform.yOffs)
|
|
|
|
("xscale", p.xform.xScale, def->xform.xScale)
|
|
|
|
("yscale", p.xform.yScale, def->xform.yScale)
|
|
|
|
("angle", p.xform.Angle, def->xform.Angle)
|
|
|
|
("baseyoffs", p.xform.baseyOffs, def->xform.baseyOffs)
|
|
|
|
("baseangle", p.xform.baseAngle, def->xform.baseAngle)
|
|
|
|
("flags", p.Flags, def->Flags)
|
|
|
|
("light", p.Light, def->Light)
|
|
|
|
("texture", p.Texture, def->Texture)
|
|
|
|
("texz", p.TexZ, def->TexZ)
|
|
|
|
("alpha", p.alpha, def->alpha)
|
2016-12-28 20:35:42 +00:00
|
|
|
("glowcolor", p.GlowColor, def->GlowColor)
|
|
|
|
("glowheight", p.GlowHeight, def->GlowHeight)
|
2016-09-19 08:34:54 +00:00
|
|
|
.EndObject();
|
|
|
|
}
|
|
|
|
return arc;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
2016-09-19 08:34:54 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
FSerializer &Serialize(FSerializer &arc, const char *key, secplane_t &p, secplane_t *def)
|
2016-04-20 17:42:00 +00:00
|
|
|
{
|
2016-09-19 08:34:54 +00:00
|
|
|
if (arc.canSkip() && def != nullptr && !memcmp(&p, def, sizeof(p)))
|
|
|
|
{
|
|
|
|
return arc;
|
|
|
|
}
|
2016-04-20 17:42:00 +00:00
|
|
|
|
2016-09-19 08:34:54 +00:00
|
|
|
if (arc.BeginObject(key))
|
2016-04-20 17:42:00 +00:00
|
|
|
{
|
2016-09-23 21:47:25 +00:00
|
|
|
Serialize(arc, "normal", p.normal, def ? &def->normal : nullptr);
|
|
|
|
Serialize(arc, "d", p.D, def ? &def->D : nullptr);
|
|
|
|
arc.EndObject();
|
2016-09-19 08:34:54 +00:00
|
|
|
|
|
|
|
if (arc.isReading() && p.normal.Z != 0)
|
|
|
|
{
|
2016-09-23 21:47:25 +00:00
|
|
|
p.negiC = -1 / p.normal.Z;
|
2016-09-19 08:34:54 +00:00
|
|
|
}
|
2016-04-20 17:42:00 +00:00
|
|
|
}
|
2016-09-19 08:34:54 +00:00
|
|
|
return arc;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
FSerializer &Serialize(FSerializer &arc, const char *key, sector_t &p, sector_t *def)
|
|
|
|
{
|
|
|
|
if (arc.BeginObject(key))
|
2016-04-20 17:42:00 +00:00
|
|
|
{
|
2016-09-19 08:34:54 +00:00
|
|
|
arc("floorplane", p.floorplane, def->floorplane)
|
|
|
|
("ceilingplane", p.ceilingplane, def->ceilingplane)
|
|
|
|
("lightlevel", p.lightlevel, def->lightlevel)
|
|
|
|
("special", p.special, def->special)
|
|
|
|
("seqtype", p.seqType, def->seqType)
|
|
|
|
("seqname", p.SeqName, def->SeqName)
|
|
|
|
("friction", p.friction, def->friction)
|
|
|
|
("movefactor", p.movefactor, def->movefactor)
|
|
|
|
("stairlock", p.stairlock, def->stairlock)
|
|
|
|
("prevsec", p.prevsec, def->prevsec)
|
|
|
|
("nextsec", p.nextsec, def->nextsec)
|
|
|
|
.Array("planes", p.planes, def->planes, 2, true)
|
|
|
|
// These cannot change during play.
|
|
|
|
//("heightsec", p.heightsec)
|
|
|
|
//("bottommap", p.bottommap)
|
|
|
|
//("midmap", p.midmap)
|
|
|
|
//("topmap", p.topmap)
|
|
|
|
("damageamount", p.damageamount, def->damageamount)
|
|
|
|
("damageinterval", p.damageinterval, def->damageinterval)
|
|
|
|
("leakydamage", p.leakydamage, def->leakydamage)
|
|
|
|
("damagetype", p.damagetype, def->damagetype)
|
|
|
|
("sky", p.sky, def->sky)
|
|
|
|
("moreflags", p.MoreFlags, def->MoreFlags)
|
|
|
|
("flags", p.Flags, def->Flags)
|
|
|
|
.Array("portals", p.Portals, def->Portals, 2, true)
|
|
|
|
("zonenumber", p.ZoneNumber, def->ZoneNumber)
|
|
|
|
.Array("interpolations", p.interpolations, 4, true)
|
|
|
|
("soundtarget", p.SoundTarget)
|
|
|
|
("secacttarget", p.SecActTarget)
|
|
|
|
("floordata", p.floordata)
|
|
|
|
("ceilingdata", p.ceilingdata)
|
|
|
|
("lightingdata", p.lightingdata)
|
|
|
|
("fakefloor_sectors", p.e->FakeFloor.Sectors)
|
|
|
|
("midtexf_lines", p.e->Midtex.Floor.AttachedLines)
|
|
|
|
("midtexf_sectors", p.e->Midtex.Floor.AttachedSectors)
|
|
|
|
("midtexc_lines", p.e->Midtex.Ceiling.AttachedLines)
|
|
|
|
("midtexc_sectors", p.e->Midtex.Ceiling.AttachedSectors)
|
|
|
|
("linked_floor", p.e->Linked.Floor.Sectors)
|
|
|
|
("linked_ceiling", p.e->Linked.Ceiling.Sectors)
|
2017-03-15 15:47:42 +00:00
|
|
|
("colormap", p.Colormap, def->Colormap)
|
2018-12-21 00:03:52 +00:00
|
|
|
.Array("specialcolors", p.SpecialColors, def->SpecialColors, 5, true)
|
|
|
|
.Array("additivecolors", p.AdditiveColors, def->AdditiveColors, 5, true)
|
2017-01-13 22:29:52 +00:00
|
|
|
("gravity", p.gravity, def->gravity)
|
2016-09-19 08:34:54 +00:00
|
|
|
.Terrain("floorterrain", p.terrainnum[0], &def->terrainnum[0])
|
|
|
|
.Terrain("ceilingterrain", p.terrainnum[1], &def->terrainnum[1])
|
2018-10-31 20:40:08 +00:00
|
|
|
("healthfloor", p.healthfloor, def->healthfloor)
|
|
|
|
("healthceiling", p.healthceiling, def->healthceiling)
|
2018-11-04 04:53:37 +00:00
|
|
|
("health3d", p.health3d, def->health3d)
|
2016-09-23 23:47:44 +00:00
|
|
|
// GZDoom exclusive:
|
2017-03-18 12:25:22 +00:00
|
|
|
.Array("reflect", p.reflect, def->reflect, 2, true)
|
2016-09-19 08:34:54 +00:00
|
|
|
.EndObject();
|
2016-04-20 17:42:00 +00:00
|
|
|
}
|
2016-09-19 08:34:54 +00:00
|
|
|
return arc;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// RecalculateDrawnSubsectors
|
|
|
|
//
|
|
|
|
// In case the subsector data is unusable this function tries to reconstruct
|
|
|
|
// if from the linedefs' ML_MAPPED info.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2019-01-26 16:55:15 +00:00
|
|
|
void FLevelLocals::RecalculateDrawnSubsectors()
|
2016-09-19 08:34:54 +00:00
|
|
|
{
|
2019-01-26 16:55:15 +00:00
|
|
|
for (auto &sub : subsectors)
|
2016-04-29 09:44:17 +00:00
|
|
|
{
|
2017-03-16 23:22:52 +00:00
|
|
|
for (unsigned int j = 0; j<sub.numlines; j++)
|
2016-04-29 09:44:17 +00:00
|
|
|
{
|
2017-03-16 23:22:52 +00:00
|
|
|
if (sub.firstline[j].linedef != NULL &&
|
|
|
|
(sub.firstline[j].linedef->flags & ML_MAPPED))
|
2016-04-29 09:44:17 +00:00
|
|
|
{
|
2018-05-01 09:29:29 +00:00
|
|
|
sub.flags |= SSECMF_DRAWN;
|
2016-04-29 09:44:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-20 17:42:00 +00:00
|
|
|
}
|
|
|
|
|
2016-09-19 08:34:54 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2019-01-26 16:55:15 +00:00
|
|
|
FSerializer &FLevelLocals::SerializeSubsectors(FSerializer &arc, const char *key)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2017-03-08 14:20:00 +00:00
|
|
|
uint8_t by;
|
2016-09-19 08:34:54 +00:00
|
|
|
const char *str;
|
|
|
|
|
2019-01-26 16:55:15 +00:00
|
|
|
auto numsubsectors = subsectors.Size();
|
2016-09-19 08:34:54 +00:00
|
|
|
if (arc.isWriting())
|
|
|
|
{
|
2018-12-20 17:40:19 +00:00
|
|
|
TArray<char> encoded(1 + (numsubsectors + 5) / 6);
|
|
|
|
int p = 0;
|
|
|
|
for (unsigned i = 0; i < numsubsectors; i += 6)
|
2016-09-19 08:34:54 +00:00
|
|
|
{
|
2018-12-20 17:40:19 +00:00
|
|
|
by = 0;
|
|
|
|
for (unsigned j = 0; j < 6; j++)
|
2016-09-19 08:34:54 +00:00
|
|
|
{
|
2019-01-26 16:55:15 +00:00
|
|
|
if (i + j < numsubsectors && (subsectors[i + j].flags & SSECMF_DRAWN))
|
2016-09-19 08:34:54 +00:00
|
|
|
{
|
2018-12-20 17:40:19 +00:00
|
|
|
by |= (1 << j);
|
2016-09-19 08:34:54 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-20 17:40:19 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
encoded[p] = 0;
|
|
|
|
str = &encoded[0];
|
|
|
|
if (arc.BeginArray(key))
|
|
|
|
{
|
2019-01-26 16:55:15 +00:00
|
|
|
auto numvertexes = vertexes.Size();
|
2018-12-20 17:40:19 +00:00
|
|
|
arc(nullptr, numvertexes)
|
|
|
|
(nullptr, numsubsectors)
|
|
|
|
.StringPtr(nullptr, str)
|
|
|
|
.EndArray();
|
2016-09-19 08:34:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int num_verts, num_subs;
|
|
|
|
bool success = false;
|
|
|
|
if (arc.BeginArray(key))
|
|
|
|
{
|
|
|
|
arc(nullptr, num_verts)
|
|
|
|
(nullptr, num_subs)
|
|
|
|
.StringPtr(nullptr, str)
|
|
|
|
.EndArray();
|
|
|
|
|
2019-01-26 16:55:15 +00:00
|
|
|
if (num_verts == (int)vertexes.Size() && num_subs == (int)numsubsectors)
|
2016-09-19 08:34:54 +00:00
|
|
|
{
|
|
|
|
success = true;
|
2016-09-20 11:30:31 +00:00
|
|
|
int sub = 0;
|
2016-09-19 08:34:54 +00:00
|
|
|
for (int i = 0; str[i] != 0; i++)
|
|
|
|
{
|
|
|
|
by = str[i];
|
|
|
|
if (by >= '0' && by <= '9') by -= '0';
|
|
|
|
else if (by >= 'A' && by <= 'Z') by -= 'A' - 10;
|
|
|
|
else if (by >= 'a' && by <= 'z') by -= 'a' - 36;
|
|
|
|
else if (by == '-') by = 62;
|
|
|
|
else if (by == '+') by = 63;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
break;
|
|
|
|
}
|
2016-09-20 11:30:31 +00:00
|
|
|
for (int s = 0; s < 6; s++)
|
|
|
|
{
|
2017-03-16 23:22:52 +00:00
|
|
|
if (sub + s < (int)numsubsectors && (by & (1 << s)))
|
2016-09-20 11:30:31 +00:00
|
|
|
{
|
2019-01-26 16:55:15 +00:00
|
|
|
subsectors[sub + s].flags |= SSECMF_DRAWN;
|
2016-09-20 11:30:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
sub += 6;
|
2016-09-19 08:34:54 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-20 17:40:19 +00:00
|
|
|
if (!success)
|
2016-09-19 08:34:54 +00:00
|
|
|
{
|
|
|
|
RecalculateDrawnSubsectors();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2016-03-01 15:47:10 +00:00
|
|
|
return arc;
|
|
|
|
}
|
|
|
|
|
2016-09-19 08:34:54 +00:00
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// Save a line portal for savegames.
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
FSerializer &Serialize(FSerializer &arc, const char *key, FLinePortal &port, FLinePortal *def)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-09-19 08:34:54 +00:00
|
|
|
if (arc.BeginObject(key))
|
|
|
|
{
|
|
|
|
arc("origin", port.mOrigin)
|
|
|
|
("destination", port.mDestination)
|
|
|
|
("displacement", port.mDisplacement)
|
|
|
|
("type", port.mType)
|
|
|
|
("flags", port.mFlags)
|
|
|
|
("defflags", port.mDefFlags)
|
|
|
|
("align", port.mAlign)
|
|
|
|
.EndObject();
|
|
|
|
}
|
2016-03-01 15:47:10 +00:00
|
|
|
return arc;
|
|
|
|
}
|
|
|
|
|
2016-09-19 08:34:54 +00:00
|
|
|
//============================================================================
|
2016-03-01 15:47:10 +00:00
|
|
|
//
|
2016-09-19 08:34:54 +00:00
|
|
|
// Save a sector portal for savegames.
|
2016-03-01 15:47:10 +00:00
|
|
|
//
|
2016-09-19 08:34:54 +00:00
|
|
|
//============================================================================
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-09-19 08:34:54 +00:00
|
|
|
FSerializer &Serialize(FSerializer &arc, const char *key, FSectorPortal &port, FSectorPortal *def)
|
|
|
|
{
|
|
|
|
if (arc.BeginObject(key))
|
|
|
|
{
|
|
|
|
arc("type", port.mType)
|
|
|
|
("flags", port.mFlags)
|
|
|
|
("partner", port.mPartner)
|
|
|
|
("plane", port.mPlane)
|
|
|
|
("origin", port.mOrigin)
|
|
|
|
("destination", port.mDestination)
|
|
|
|
("displacement", port.mDisplacement)
|
|
|
|
("planez", port.mPlaneZ)
|
|
|
|
("skybox", port.mSkybox)
|
|
|
|
.EndObject();
|
|
|
|
}
|
|
|
|
return arc;
|
|
|
|
}
|
|
|
|
|
2016-09-20 07:11:13 +00:00
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// one polyobject.
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
FSerializer &Serialize(FSerializer &arc, const char *key, FPolyObj &poly, FPolyObj *def)
|
|
|
|
{
|
|
|
|
if (arc.BeginObject(key))
|
|
|
|
{
|
|
|
|
DAngle angle = poly.Angle;
|
|
|
|
DVector2 delta = poly.StartSpot.pos;
|
|
|
|
arc("angle", angle)
|
|
|
|
("pos", delta)
|
|
|
|
("interpolation", poly.interpolation)
|
|
|
|
("blocked", poly.bBlocked)
|
|
|
|
("hasportals", poly.bHasPortals)
|
|
|
|
("specialdata", poly.specialdata)
|
|
|
|
.EndObject();
|
|
|
|
|
|
|
|
if (arc.isReading())
|
|
|
|
{
|
|
|
|
poly.RotatePolyobj(angle, true);
|
|
|
|
delta -= poly.StartSpot.pos;
|
|
|
|
poly.MovePolyobj(delta, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return arc;
|
|
|
|
}
|
|
|
|
|
2016-09-19 08:34:54 +00:00
|
|
|
//==========================================================================
|
2016-03-01 15:47:10 +00:00
|
|
|
//
|
|
|
|
//
|
2016-09-19 08:34:54 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-09-19 08:34:54 +00:00
|
|
|
FSerializer &Serialize(FSerializer &arc, const char *key, ReverbContainer *&c, ReverbContainer **def)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-09-19 08:34:54 +00:00
|
|
|
int id = (arc.isReading() || c == nullptr) ? 0 : c->ID;
|
|
|
|
Serialize(arc, key, id, nullptr);
|
|
|
|
if (arc.isReading())
|
|
|
|
{
|
|
|
|
c = S_FindEnvironment(id);
|
|
|
|
}
|
|
|
|
return arc;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
2016-09-19 08:34:54 +00:00
|
|
|
FSerializer &Serialize(FSerializer &arc, const char *key, zone_t &z, zone_t *def)
|
2016-06-01 09:43:56 +00:00
|
|
|
{
|
2016-09-19 08:34:54 +00:00
|
|
|
return Serialize(arc, key, z.Environment, nullptr);
|
|
|
|
}
|
|
|
|
|
2016-09-20 21:13:12 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// ArchiveSounds
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2019-01-27 20:59:19 +00:00
|
|
|
void P_SerializeSounds(FLevelLocals *Level, FSerializer &arc)
|
2016-09-20 21:13:12 +00:00
|
|
|
{
|
|
|
|
S_SerializeSounds(arc);
|
2016-09-23 18:05:12 +00:00
|
|
|
const char *name = NULL;
|
2017-03-08 14:20:00 +00:00
|
|
|
uint8_t order;
|
2019-01-27 20:59:19 +00:00
|
|
|
float musvol = Level->MusicVolume;
|
2016-09-20 21:13:12 +00:00
|
|
|
|
|
|
|
if (arc.isWriting())
|
|
|
|
{
|
2016-09-23 19:24:56 +00:00
|
|
|
order = S_GetMusic(&name);
|
2016-09-20 21:13:12 +00:00
|
|
|
}
|
2016-09-23 18:05:12 +00:00
|
|
|
arc.StringPtr("musicname", name)
|
2018-03-24 12:06:37 +00:00
|
|
|
("musicorder", order)
|
|
|
|
("musicvolume", musvol);
|
2016-09-20 21:13:12 +00:00
|
|
|
|
|
|
|
if (arc.isReading())
|
|
|
|
{
|
|
|
|
if (!S_ChangeMusic(name, order))
|
2019-01-28 00:25:52 +00:00
|
|
|
Level->SetMusic();
|
2019-01-27 20:59:19 +00:00
|
|
|
Level->SetMusicVolume(musvol);
|
2016-09-20 21:13:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void CopyPlayer(player_t *dst, player_t *src, const char *name);
|
|
|
|
static void ReadOnePlayer(FSerializer &arc, bool skipload);
|
|
|
|
static void ReadMultiplePlayers(FSerializer &arc, int numPlayers, int numPlayersNow, bool skipload);
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// P_ArchivePlayers
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2019-01-24 00:05:07 +00:00
|
|
|
void P_SerializePlayers(FLevelLocals *Level, FSerializer &arc, bool skipload)
|
2016-09-20 21:13:12 +00:00
|
|
|
{
|
2016-09-20 23:18:29 +00:00
|
|
|
int numPlayers, numPlayersNow;
|
2016-09-20 21:13:12 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
// Count the number of players present right now.
|
|
|
|
for (numPlayersNow = 0, i = 0; i < MAXPLAYERS; ++i)
|
|
|
|
{
|
2019-01-30 00:15:32 +00:00
|
|
|
if (Level->PlayerInGame(i))
|
2016-09-20 21:13:12 +00:00
|
|
|
{
|
|
|
|
++numPlayersNow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arc.isWriting())
|
|
|
|
{
|
|
|
|
// Record the number of players in this save.
|
2016-09-20 23:18:29 +00:00
|
|
|
arc("numplayers", numPlayersNow);
|
|
|
|
if (arc.BeginArray("players"))
|
2016-09-20 21:13:12 +00:00
|
|
|
{
|
2016-09-20 23:18:29 +00:00
|
|
|
// Record each player's name, followed by their data.
|
|
|
|
for (i = 0; i < MAXPLAYERS; ++i)
|
2016-09-20 21:13:12 +00:00
|
|
|
{
|
2016-09-20 23:18:29 +00:00
|
|
|
if (playeringame[i])
|
|
|
|
{
|
|
|
|
if (arc.BeginObject(nullptr))
|
|
|
|
{
|
|
|
|
const char *n = players[i].userinfo.GetName();
|
|
|
|
arc.StringPtr("playername", n);
|
|
|
|
players[i].Serialize(arc);
|
|
|
|
arc.EndObject();
|
|
|
|
}
|
|
|
|
}
|
2016-09-20 21:13:12 +00:00
|
|
|
}
|
2016-09-20 23:18:29 +00:00
|
|
|
arc.EndArray();
|
2016-09-20 21:13:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-20 23:18:29 +00:00
|
|
|
arc("numplayers", numPlayers);
|
2016-09-20 21:13:12 +00:00
|
|
|
|
2016-09-20 23:18:29 +00:00
|
|
|
if (arc.BeginArray("players"))
|
2016-09-20 21:13:12 +00:00
|
|
|
{
|
2016-09-20 23:18:29 +00:00
|
|
|
// If there is only one player in the game, they go to the
|
|
|
|
// first player present, no matter what their name.
|
|
|
|
if (numPlayers == 1)
|
|
|
|
{
|
|
|
|
ReadOnePlayer(arc, skipload);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ReadMultiplePlayers(arc, numPlayers, numPlayersNow, skipload);
|
|
|
|
}
|
2016-09-23 18:05:12 +00:00
|
|
|
arc.EndArray();
|
2016-09-20 21:13:12 +00:00
|
|
|
}
|
|
|
|
if (!skipload && numPlayersNow > numPlayers)
|
|
|
|
{
|
2019-01-26 16:55:15 +00:00
|
|
|
Level->SpawnExtraPlayers();
|
2016-09-20 21:13:12 +00:00
|
|
|
}
|
|
|
|
// Redo pitch limits, since the spawned player has them at 0.
|
2019-02-01 16:02:10 +00:00
|
|
|
auto p = Level->GetConsolePlayer();
|
|
|
|
if (p) p->SendPitchLimits();
|
2016-09-20 21:13:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
static void ReadOnePlayer(FSerializer &arc, bool skipload)
|
|
|
|
{
|
|
|
|
int i;
|
2016-09-20 23:18:29 +00:00
|
|
|
const char *name = NULL;
|
2016-09-20 21:13:12 +00:00
|
|
|
bool didIt = false;
|
|
|
|
|
2016-09-20 23:18:29 +00:00
|
|
|
if (arc.BeginObject(nullptr))
|
2016-09-20 21:13:12 +00:00
|
|
|
{
|
2016-09-20 23:18:29 +00:00
|
|
|
arc.StringPtr("playername", name);
|
|
|
|
|
|
|
|
for (i = 0; i < MAXPLAYERS; ++i)
|
2016-09-20 21:13:12 +00:00
|
|
|
{
|
2016-09-20 23:18:29 +00:00
|
|
|
if (playeringame[i])
|
2016-09-20 21:13:12 +00:00
|
|
|
{
|
2016-09-20 23:18:29 +00:00
|
|
|
if (!didIt)
|
2016-09-20 21:13:12 +00:00
|
|
|
{
|
2016-09-20 23:18:29 +00:00
|
|
|
didIt = true;
|
|
|
|
player_t playerTemp;
|
|
|
|
playerTemp.Serialize(arc);
|
|
|
|
if (!skipload)
|
|
|
|
{
|
2016-10-23 01:56:31 +00:00
|
|
|
// This temp player has undefined pitch limits, so set them to something
|
|
|
|
// that should leave the pitch stored in the savegame intact when
|
|
|
|
// rendering. The real pitch limits will be set by P_SerializePlayers()
|
|
|
|
// via a net command, but that won't be processed in time for a screen
|
|
|
|
// wipe, so we need something here.
|
|
|
|
playerTemp.MaxPitch = playerTemp.MinPitch = playerTemp.mo->Angles.Pitch;
|
2016-09-20 23:18:29 +00:00
|
|
|
CopyPlayer(&players[i], &playerTemp, name);
|
|
|
|
}
|
2016-09-25 07:23:44 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// we need the player actor, so that G_FinishTravel can destroy it later.
|
|
|
|
players[i].mo = playerTemp.mo;
|
|
|
|
}
|
2016-09-20 21:13:12 +00:00
|
|
|
}
|
2016-09-20 23:18:29 +00:00
|
|
|
else
|
2016-09-20 21:13:12 +00:00
|
|
|
{
|
2016-09-20 23:18:29 +00:00
|
|
|
if (players[i].mo != NULL)
|
|
|
|
{
|
|
|
|
players[i].mo->Destroy();
|
|
|
|
players[i].mo = NULL;
|
|
|
|
}
|
2016-09-20 21:13:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-23 18:05:12 +00:00
|
|
|
arc.EndObject();
|
2016-09-20 21:13:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
static void ReadMultiplePlayers(FSerializer &arc, int numPlayers, int numPlayersNow, bool skipload)
|
|
|
|
{
|
|
|
|
// For two or more players, read each player into a temporary array.
|
|
|
|
int i, j;
|
2016-09-20 23:18:29 +00:00
|
|
|
const char **nametemp = new const char *[numPlayers];
|
2016-09-20 21:13:12 +00:00
|
|
|
player_t *playertemp = new player_t[numPlayers];
|
2017-03-08 14:20:00 +00:00
|
|
|
uint8_t *tempPlayerUsed = new uint8_t[numPlayers];
|
|
|
|
uint8_t playerUsed[MAXPLAYERS];
|
2016-09-20 21:13:12 +00:00
|
|
|
|
|
|
|
for (i = 0; i < numPlayers; ++i)
|
|
|
|
{
|
|
|
|
nametemp[i] = NULL;
|
2016-09-20 23:18:29 +00:00
|
|
|
if (arc.BeginObject(nullptr))
|
|
|
|
{
|
|
|
|
arc.StringPtr("playername", nametemp[i]);
|
|
|
|
playertemp[i].Serialize(arc);
|
2016-09-23 18:05:12 +00:00
|
|
|
arc.EndObject();
|
2016-09-20 23:18:29 +00:00
|
|
|
}
|
2016-09-20 21:13:12 +00:00
|
|
|
tempPlayerUsed[i] = 0;
|
|
|
|
}
|
|
|
|
for (i = 0; i < MAXPLAYERS; ++i)
|
|
|
|
{
|
|
|
|
playerUsed[i] = playeringame[i] ? 0 : 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!skipload)
|
|
|
|
{
|
|
|
|
// Now try to match players from the savegame with players present
|
|
|
|
// based on their names. If two players in the savegame have the
|
|
|
|
// same name, then they are assigned to players in the current game
|
|
|
|
// on a first-come, first-served basis.
|
|
|
|
for (i = 0; i < numPlayers; ++i)
|
|
|
|
{
|
|
|
|
for (j = 0; j < MAXPLAYERS; ++j)
|
|
|
|
{
|
|
|
|
if (playerUsed[j] == 0 && stricmp(players[j].userinfo.GetName(), nametemp[i]) == 0)
|
|
|
|
{ // Found a match, so copy our temp player to the real player
|
|
|
|
Printf("Found player %d (%s) at %d\n", i, nametemp[i], j);
|
|
|
|
CopyPlayer(&players[j], &playertemp[i], nametemp[i]);
|
|
|
|
playerUsed[j] = 1;
|
|
|
|
tempPlayerUsed[i] = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Any players that didn't have matching names are assigned to existing
|
|
|
|
// players on a first-come, first-served basis.
|
|
|
|
for (i = 0; i < numPlayers; ++i)
|
|
|
|
{
|
|
|
|
if (tempPlayerUsed[i] == 0)
|
|
|
|
{
|
|
|
|
for (j = 0; j < MAXPLAYERS; ++j)
|
|
|
|
{
|
|
|
|
if (playerUsed[j] == 0)
|
|
|
|
{
|
|
|
|
Printf("Assigned player %d (%s) to %d (%s)\n", i, nametemp[i], j, players[j].userinfo.GetName());
|
|
|
|
CopyPlayer(&players[j], &playertemp[i], nametemp[i]);
|
|
|
|
playerUsed[j] = 1;
|
|
|
|
tempPlayerUsed[i] = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure any extra players don't have actors spawned yet. Happens if the players
|
|
|
|
// present now got the same slots as they had in the save, but there are not as many
|
|
|
|
// as there were in the save.
|
|
|
|
for (j = 0; j < MAXPLAYERS; ++j)
|
|
|
|
{
|
|
|
|
if (playerUsed[j] == 0)
|
|
|
|
{
|
|
|
|
if (players[j].mo != NULL)
|
|
|
|
{
|
|
|
|
players[j].mo->Destroy();
|
|
|
|
players[j].mo = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove any temp players that were not used. Happens if there are fewer players
|
|
|
|
// than there were in the save, and they got shuffled.
|
|
|
|
for (i = 0; i < numPlayers; ++i)
|
|
|
|
{
|
|
|
|
if (tempPlayerUsed[i] == 0)
|
|
|
|
{
|
|
|
|
playertemp[i].mo->Destroy();
|
|
|
|
playertemp[i].mo = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-25 07:23:44 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < MAXPLAYERS; ++i)
|
|
|
|
{
|
|
|
|
players[i].mo = playertemp[i].mo;
|
|
|
|
}
|
|
|
|
}
|
2016-09-20 21:13:12 +00:00
|
|
|
|
|
|
|
delete[] tempPlayerUsed;
|
|
|
|
delete[] playertemp;
|
|
|
|
delete[] nametemp;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void CopyPlayer(player_t *dst, player_t *src, const char *name)
|
|
|
|
{
|
|
|
|
// The userinfo needs to be saved for real players, but it
|
|
|
|
// needs to come from the save for bots.
|
|
|
|
userinfo_t uibackup;
|
|
|
|
userinfo_t uibackup2;
|
|
|
|
|
|
|
|
uibackup.TransferFrom(dst->userinfo);
|
|
|
|
uibackup2.TransferFrom(src->userinfo);
|
|
|
|
|
|
|
|
int chasecam = dst->cheats & CF_CHASECAM; // Remember the chasecam setting
|
|
|
|
bool attackdown = dst->attackdown;
|
|
|
|
bool usedown = dst->usedown;
|
|
|
|
|
|
|
|
|
|
|
|
*dst = *src; // To avoid memory leaks at this point the userinfo in src must be empty which is taken care of by the TransferFrom call above.
|
|
|
|
|
|
|
|
dst->cheats |= chasecam;
|
|
|
|
|
|
|
|
if (dst->Bot != nullptr)
|
|
|
|
{
|
2019-01-30 00:38:18 +00:00
|
|
|
botinfo_t *thebot = level.BotInfo.botinfo;
|
2016-09-20 21:13:12 +00:00
|
|
|
while (thebot && stricmp(name, thebot->name))
|
|
|
|
{
|
|
|
|
thebot = thebot->next;
|
|
|
|
}
|
|
|
|
if (thebot)
|
|
|
|
{
|
|
|
|
thebot->inuse = BOTINUSE_Yes;
|
|
|
|
}
|
2019-01-30 00:38:18 +00:00
|
|
|
level.BotInfo.botnum++;
|
2016-09-20 21:13:12 +00:00
|
|
|
dst->userinfo.TransferFrom(uibackup2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dst->userinfo.TransferFrom(uibackup);
|
2017-02-15 10:55:08 +00:00
|
|
|
// The player class must come from the save, so that the menu reflects the currently playing one.
|
2017-04-11 22:07:41 +00:00
|
|
|
dst->userinfo.PlayerClassChanged(src->mo->GetInfo()->DisplayName);
|
2016-09-20 21:13:12 +00:00
|
|
|
}
|
2017-02-15 10:55:08 +00:00
|
|
|
|
2016-09-20 21:13:12 +00:00
|
|
|
// Validate the skin
|
2017-02-17 20:51:23 +00:00
|
|
|
dst->userinfo.SkinNumChanged(R_FindSkin(Skins[dst->userinfo.GetSkin()].Name, dst->CurrentPlayerClass));
|
2016-09-20 21:13:12 +00:00
|
|
|
|
|
|
|
// Make sure the player pawn points to the proper player struct.
|
|
|
|
if (dst->mo != nullptr)
|
|
|
|
{
|
|
|
|
dst->mo->player = dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Same for the psprites.
|
|
|
|
DPSprite *pspr = dst->psprites;
|
|
|
|
while (pspr)
|
|
|
|
{
|
|
|
|
pspr->Owner = dst;
|
|
|
|
|
|
|
|
pspr = pspr->Next;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't let the psprites be destroyed when src is destroyed.
|
|
|
|
src->psprites = nullptr;
|
|
|
|
|
|
|
|
// These 2 variables may not be overwritten.
|
|
|
|
dst->attackdown = attackdown;
|
|
|
|
dst->usedown = usedown;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2019-01-26 16:55:15 +00:00
|
|
|
void FLevelLocals::SpawnExtraPlayers()
|
2016-09-20 21:13:12 +00:00
|
|
|
{
|
|
|
|
// If there are more players now than there were in the savegame,
|
|
|
|
// be sure to spawn the extra players.
|
|
|
|
int i;
|
|
|
|
|
2019-01-30 00:15:32 +00:00
|
|
|
if (deathmatch || !isPrimaryLevel())
|
2016-09-20 21:13:12 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < MAXPLAYERS; ++i)
|
|
|
|
{
|
2019-01-30 00:15:32 +00:00
|
|
|
if (PlayerInGame(i) && Players[i]->mo == NULL)
|
2016-09-20 21:13:12 +00:00
|
|
|
{
|
2019-01-30 00:15:32 +00:00
|
|
|
Players[i]->playerstate = PST_ENTER;
|
2019-01-28 02:02:25 +00:00
|
|
|
SpawnPlayer(&playerstarts[i], i, (flags2 & LEVEL2_PRERAISEWEAPON) ? SPF_WEAPONFULLYUP : 0);
|
2016-09-20 21:13:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
2016-09-19 08:34:54 +00:00
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
2019-01-26 16:55:15 +00:00
|
|
|
void FLevelLocals::Serialize(FSerializer &arc, bool hubload)
|
2016-09-19 08:34:54 +00:00
|
|
|
{
|
2019-01-26 16:55:15 +00:00
|
|
|
int i = totaltime;
|
2016-09-20 07:11:13 +00:00
|
|
|
|
|
|
|
if (arc.isWriting())
|
|
|
|
{
|
2019-01-26 16:55:15 +00:00
|
|
|
arc.Array("checksum", md5, 16);
|
2016-09-20 07:11:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// prevent bad things from happening by doing a check on the size of level arrays and the map's entire checksum.
|
|
|
|
// The old code happily tried to load savegames with any mismatch here, often causing meaningless errors
|
|
|
|
// deep down in the deserializer or just a crash if the few insufficient safeguards were not triggered.
|
2017-03-08 14:20:00 +00:00
|
|
|
uint8_t chk[16] = { 0 };
|
2016-09-20 07:11:13 +00:00
|
|
|
arc.Array("checksum", chk, 16);
|
2019-01-26 16:55:15 +00:00
|
|
|
if (arc.GetSize("linedefs") != lines.Size() ||
|
|
|
|
arc.GetSize("sidedefs") != sides.Size() ||
|
|
|
|
arc.GetSize("sectors") != sectors.Size() ||
|
|
|
|
arc.GetSize("polyobjs") != Polyobjects.Size() ||
|
|
|
|
memcmp(chk, md5, 16))
|
2016-09-20 07:11:13 +00:00
|
|
|
{
|
|
|
|
I_Error("Savegame is from a different level");
|
|
|
|
}
|
|
|
|
}
|
2016-09-21 15:37:56 +00:00
|
|
|
arc("saveversion", SaveVersion);
|
2016-09-20 07:11:13 +00:00
|
|
|
|
|
|
|
if (arc.isReading())
|
|
|
|
{
|
2019-01-30 01:15:48 +00:00
|
|
|
Thinkers.DestroyAllThinkers();
|
- removed the sequential processing of JSON objects because the benefit is too small.
After testing with a savegame on ZDCMP2 which is probably the largest map in existence, timing both methods resulted in a speed difference of less than 40 ms (70 vs 110 ms for reading all sectory, linedefs, sidedefs and objects).
This compares to an overall restoration time, including reloading the level, precaching all textures and setting everything up, of approx. 1.2 s, meaning an increase of 3% of the entire reloading time.
That's simply not worth all the negative side effects that may happen with a method that highly depends on proper code construction.
On the other hand, using random access means that a savegame version change is only needed now when the semantics of a field change, but not if some get added or deleted.
- do not I_Error out in the serializer unless caused by a programming error.
It is better to let the serializer finish, collect all the errors and I_Error out when the game is known to be in a stable enough state to allow unwinding.
2016-09-23 12:04:05 +00:00
|
|
|
interpolator.ClearInterpolations();
|
2016-09-23 15:49:33 +00:00
|
|
|
arc.ReadObjects(hubload);
|
2019-01-28 22:53:40 +00:00
|
|
|
ActiveSequences = 0;
|
2016-09-20 07:11:13 +00:00
|
|
|
}
|
|
|
|
|
2018-09-15 12:16:02 +00:00
|
|
|
arc("multiplayer", multiplayer);
|
|
|
|
|
2019-01-26 16:55:15 +00:00
|
|
|
arc("flags", flags)
|
|
|
|
("flags2", flags2)
|
|
|
|
("fadeto", fadeto)
|
|
|
|
("found_secrets", found_secrets)
|
|
|
|
("found_items", found_items)
|
|
|
|
("killed_monsters", killed_monsters)
|
|
|
|
("total_secrets", total_secrets)
|
|
|
|
("total_items", total_items)
|
|
|
|
("total_monsters", total_monsters)
|
|
|
|
("gravity", gravity)
|
|
|
|
("aircontrol", aircontrol)
|
|
|
|
("teamdamage", teamdamage)
|
|
|
|
("maptime", maptime)
|
2019-01-24 00:05:07 +00:00
|
|
|
("totaltime", i)
|
2019-01-26 16:55:15 +00:00
|
|
|
("skytexture1", skytexture1)
|
|
|
|
("skytexture2", skytexture2)
|
|
|
|
("fogdensity", fogdensity)
|
|
|
|
("outsidefogdensity", outsidefogdensity)
|
|
|
|
("skyfog", skyfog)
|
|
|
|
("deathsequence", deathsequence)
|
|
|
|
("bodyqueslot", bodyqueslot)
|
|
|
|
("spawnindex", spawnindex)
|
|
|
|
.Array("bodyque", bodyque, BODYQUESIZE)
|
|
|
|
("corpsequeue", CorpseQueue)
|
|
|
|
("spotstate", SpotState)
|
|
|
|
("fragglethinker", FraggleScriptThinker)
|
|
|
|
("acsthinker", ACSThinker)
|
2019-01-28 17:26:14 +00:00
|
|
|
("impactdecalcount", ImpactDecalCount)
|
2019-01-26 16:55:15 +00:00
|
|
|
("scrolls", Scrolls)
|
2019-01-28 17:26:14 +00:00
|
|
|
("automap", automap)
|
2019-01-28 19:15:48 +00:00
|
|
|
("interpolator", interpolator)
|
2019-01-28 22:53:40 +00:00
|
|
|
("frozenstate", frozenstate)
|
|
|
|
("sndseqlisthead", SequenceListHead);
|
2019-01-24 00:05:07 +00:00
|
|
|
|
2016-09-20 07:11:13 +00:00
|
|
|
|
|
|
|
// Hub transitions must keep the current total time
|
|
|
|
if (!hubload)
|
2019-01-26 16:55:15 +00:00
|
|
|
totaltime = i;
|
2016-09-20 07:11:13 +00:00
|
|
|
|
|
|
|
if (arc.isReading())
|
|
|
|
{
|
2019-01-29 03:44:44 +00:00
|
|
|
InitSkyMap(this);
|
2019-01-27 20:59:19 +00:00
|
|
|
AirControlChanged();
|
2016-09-20 07:11:13 +00:00
|
|
|
}
|
|
|
|
|
2019-01-26 16:55:15 +00:00
|
|
|
Behaviors.SerializeModuleStates(arc);
|
2016-09-20 11:21:41 +00:00
|
|
|
// The order here is important: First world state, then portal state, then thinkers, and last polyobjects.
|
2019-01-29 18:28:22 +00:00
|
|
|
SetCompatLineOnSide(false); // This flag should not be saved. It solely depends on current compatibility state.
|
2019-01-26 16:55:15 +00:00
|
|
|
arc("linedefs", lines, loadlines);
|
2019-01-29 18:28:22 +00:00
|
|
|
SetCompatLineOnSide(true);
|
2019-01-26 16:55:15 +00:00
|
|
|
arc("sidedefs", sides, loadsides);
|
|
|
|
arc("sectors", sectors, loadsectors);
|
|
|
|
arc("zones", Zones);
|
|
|
|
arc("lineportals", linePortals);
|
|
|
|
arc("sectorportals", sectorPortals);
|
2019-01-26 14:21:20 +00:00
|
|
|
if (arc.isReading())
|
|
|
|
{
|
2019-01-26 16:55:15 +00:00
|
|
|
FinalizePortals();
|
2019-01-26 14:21:20 +00:00
|
|
|
}
|
- removed the sequential processing of JSON objects because the benefit is too small.
After testing with a savegame on ZDCMP2 which is probably the largest map in existence, timing both methods resulted in a speed difference of less than 40 ms (70 vs 110 ms for reading all sectory, linedefs, sidedefs and objects).
This compares to an overall restoration time, including reloading the level, precaching all textures and setting everything up, of approx. 1.2 s, meaning an increase of 3% of the entire reloading time.
That's simply not worth all the negative side effects that may happen with a method that highly depends on proper code construction.
On the other hand, using random access means that a savegame version change is only needed now when the semantics of a field change, but not if some get added or deleted.
- do not I_Error out in the serializer unless caused by a programming error.
It is better to let the serializer finish, collect all the errors and I_Error out when the game is known to be in a stable enough state to allow unwinding.
2016-09-23 12:04:05 +00:00
|
|
|
|
2018-10-31 20:40:08 +00:00
|
|
|
// [ZZ] serialize health groups
|
2019-01-29 15:06:17 +00:00
|
|
|
P_SerializeHealthGroups(this, arc);
|
2017-01-23 21:05:51 +00:00
|
|
|
// [ZZ] serialize events
|
|
|
|
E_SerializeEvents(arc);
|
2019-01-30 01:15:48 +00:00
|
|
|
Thinkers.SerializeThinkers(arc, hubload);
|
2019-01-26 16:55:15 +00:00
|
|
|
arc("polyobjs", Polyobjects);
|
2017-03-16 23:22:52 +00:00
|
|
|
SerializeSubsectors(arc, "subsectors");
|
2016-09-20 11:21:41 +00:00
|
|
|
StatusBar->SerializeMessages(arc);
|
2016-09-20 17:45:32 +00:00
|
|
|
FRemapTable::StaticSerializeTranslations(arc);
|
2019-01-26 16:55:15 +00:00
|
|
|
canvasTextureInfo.Serialize(arc);
|
|
|
|
P_SerializePlayers(this, arc, hubload);
|
2019-01-27 20:59:19 +00:00
|
|
|
P_SerializeSounds(this, arc);
|
- removed the sequential processing of JSON objects because the benefit is too small.
After testing with a savegame on ZDCMP2 which is probably the largest map in existence, timing both methods resulted in a speed difference of less than 40 ms (70 vs 110 ms for reading all sectory, linedefs, sidedefs and objects).
This compares to an overall restoration time, including reloading the level, precaching all textures and setting everything up, of approx. 1.2 s, meaning an increase of 3% of the entire reloading time.
That's simply not worth all the negative side effects that may happen with a method that highly depends on proper code construction.
On the other hand, using random access means that a savegame version change is only needed now when the semantics of a field change, but not if some get added or deleted.
- do not I_Error out in the serializer unless caused by a programming error.
It is better to let the serializer finish, collect all the errors and I_Error out when the game is known to be in a stable enough state to allow unwinding.
2016-09-23 12:04:05 +00:00
|
|
|
|
2019-01-26 14:21:20 +00:00
|
|
|
// Regenerate some data that wasn't saved
|
2016-09-20 21:13:12 +00:00
|
|
|
if (arc.isReading())
|
2016-09-19 08:34:54 +00:00
|
|
|
{
|
2019-01-26 16:55:15 +00:00
|
|
|
for (auto &sec : sectors)
|
2019-01-30 18:09:21 +00:00
|
|
|
{
|
2017-01-07 18:32:24 +00:00
|
|
|
P_Recalculate3DFloors(&sec);
|
2016-09-19 08:34:54 +00:00
|
|
|
}
|
2016-09-20 07:11:13 +00:00
|
|
|
for (int i = 0; i < MAXPLAYERS; ++i)
|
2016-09-19 08:34:54 +00:00
|
|
|
{
|
2019-01-30 00:15:32 +00:00
|
|
|
if (PlayerInGame(i) && Players[i]->mo != nullptr)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2019-01-30 00:15:32 +00:00
|
|
|
FWeaponSlots::SetupWeaponSlots(Players[i]->mo);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-29 23:29:42 +00:00
|
|
|
RecreateAllAttachedLights();
|
2019-01-26 16:55:15 +00:00
|
|
|
InitPortalGroups(this);
|
2019-01-26 14:21:20 +00:00
|
|
|
|
2019-01-26 16:55:15 +00:00
|
|
|
automap->UpdateShowAllLines();
|
2019-01-26 14:21:20 +00:00
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2019-01-26 14:21:20 +00:00
|
|
|
|
2016-09-20 21:13:12 +00:00
|
|
|
}
|