- converted FInterBackground into a class so that the scripts can use it.

- fixed some issues with default value matching in savegames.
This commit is contained in:
Christoph Oelckers 2017-03-18 13:25:22 +01:00
parent 1e9ef2b1df
commit b416322032
8 changed files with 507 additions and 438 deletions

View File

@ -218,6 +218,7 @@ public:
template<class U> friend inline void GC::Mark(TObjPtr<U> &obj);
template<class U> friend FSerializer &Serialize(FSerializer &arc, const char *key, TObjPtr<U> &value, TObjPtr<U> *);
template<class U> friend FSerializer &Serialize(FSerializer &arc, const char *key, TObjPtr<U> &value, U *);
friend class DObject;
};

View File

@ -301,7 +301,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, sector_t &p, sector_t
.Terrain("ceilingterrain", p.terrainnum[1], &def->terrainnum[1])
("scrolls", scroll, nul)
// GZDoom exclusive:
.Array("reflect", p.reflect, def->reflect, 2)
.Array("reflect", p.reflect, def->reflect, 2, true)
.EndObject();
if (arc.isReading() && !scroll.isZero())

View File

@ -4159,9 +4159,14 @@ void P_SetupLevel (const char *lumpname, int position)
MapThingsUserData.Clear();
// Create a backup of the map data so the savegame code can toss out all fields that haven't changed in order to reduce processing time and file size.
level.loadsectors = level.sectors;
level.loadlines = level.lines;
level.loadsides = level.sides;
// Note that we want binary identity here, so assignment is not sufficient because it won't initialize any padding bytes.
// Note that none of these structures may contain non POD fields anyway.
level.loadsectors.Resize(level.sectors.Size());
memcpy(&level.loadsectors[0], &level.sectors[0], level.sectors.Size() * sizeof(level.sectors[0]));
level.loadlines.Resize(level.lines.Size());
memcpy(&level.loadlines[0], &level.lines[0], level.lines.Size() * sizeof(level.lines[0]));
level.loadsides.Resize(level.sides.Size());
memcpy(&level.loadsides[0], &level.sides[0], level.sides.Size() * sizeof(level.sides[0]));
}

View File

@ -1130,8 +1130,8 @@ struct side_t
double yOffset;
double xScale;
double yScale;
FTextureID texture;
TObjPtr<DInterpolation*> interpolation;
FTextureID texture;
//int Light;
};

View File

@ -939,7 +939,6 @@ FxExpression *FxIntCast::Resolve(FCompileContext &ctx)
{
CHECKRESOLVED();
SAFE_RESOLVE(basex, ctx);
int c;
if (basex->ValueType->GetRegType() == REGT_INT)
{

View File

@ -215,8 +215,15 @@ FSerializer &Serialize(FSerializer &arc, const char *key, TObjPtr<T> &value, TOb
return arc;
}
template<class T>
FSerializer &Serialize(FSerializer &arc, const char *key, TObjPtr<T> &value, T *)
{
Serialize(arc, key, value.o, nullptr);
return arc;
}
template<class T, class TT>
FSerializer &Serialize(FSerializer &arc, const char *key, TArray<T, TT> &value, TArray<T, TT> *)
FSerializer &Serialize(FSerializer &arc, const char *key, TArray<T, TT> &value, TArray<T, TT> *def)
{
if (arc.isWriting())
{
@ -234,7 +241,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, TArray<T, TT> &value,
}
for (unsigned i = 0; i < value.Size(); i++)
{
Serialize(arc, nullptr, value[i], (T*)nullptr);
Serialize(arc, nullptr, value[i], def? &(*def)[i] : nullptr);
}
arc.EndArray();
return arc;

View File

@ -91,8 +91,10 @@ static const char *WI_Cmd[] = {
NULL
};
struct FInterBackground
class DInterBackground : public DObject
{
DECLARE_ABSTRACT_CLASS(DInterBackground, DObject)
// These animation variables, structures, etc. are used for the
// DOOM/Ultimate DOOM intermission screen animations. This is
// totally different from any sprite or texture/flat animations
@ -161,13 +163,87 @@ private:
FTexture* splat = nullptr; // splat
FTexture *background = nullptr;
wbstartstruct_t *wbs;
public:
FInterBackground(wbstartstruct_t *wbst)
DInterBackground(wbstartstruct_t *wbst);
bool LoadBackground(bool isenterpic);
void updateAnimatedBack();
void drawBackground(int state, bool drawsplat, bool snl_pointeron);
private:
bool IsExMy(const char * name)
{
// Only check for the first 3 episodes. They are the only ones with default intermission scripts.
// Level names can be upper- and lower case so use tolower to check.
return (tolower(name[0]) == 'e' && name[1] >= '1' && name[1] <= '3' && tolower(name[2]) == 'm');
}
//====================================================================
//
// Draws the splats and the 'You are here' arrows
//
//====================================================================
int MapToIndex(const char *map)
{
unsigned int i;
for (i = 0; i < lnodes.Size(); i++)
{
if (!lnodes[i].Level.CompareNoCase(map))
break;
}
return i;
}
//====================================================================
//
// Draws the splats and the 'You are here' arrows
//
//====================================================================
void drawOnLnode(int n, FTexture * c[], int numc)
{
int i;
for (i = 0; i<numc; i++)
{
int left;
int top;
int right;
int bottom;
right = c[i]->GetScaledWidth();
bottom = c[i]->GetScaledHeight();
left = lnodes[n].x - c[i]->GetScaledLeftOffset();
top = lnodes[n].y - c[i]->GetScaledTopOffset();
right += left;
bottom += top;
if (left >= 0 && right < 320 && top >= 0 && bottom < 200)
{
screen->DrawTexture(c[i], lnodes[n].x, lnodes[n].y, DTA_320x200, true, TAG_DONE);
break;
}
}
}
};
DInterBackground:: DInterBackground(wbstartstruct_t *wbst)
{
wbs = wbst;
}
DEFINE_ACTION_FUNCTION(DInterBackground, Create)
{
PARAM_PROLOGUE;
PARAM_POINTER(wbst, wbstartstruct_t);
ACTION_RETURN_POINTER(new DInterBackground(wbst));
}
};
//====================================================================
//
// Loads the background - either from a single texture
@ -177,14 +253,8 @@ public:
// MAPINFO.
//
//====================================================================
bool IsExMy(const char * name)
{
// Only check for the first 3 episodes. They are the only ones with default intermission scripts.
// Level names can be upper- and lower case so use tolower to check!
return (tolower(name[0]) == 'e' && name[1] >= '1' && name[1] <= '3' && tolower(name[2]) == 'm');
}
bool LoadBackground(bool isenterpic)
bool DInterBackground::LoadBackground(bool isenterpic)
{
const char *lumpname = NULL;
char buffer[10];
@ -452,6 +522,13 @@ public:
return noautostartmap;
}
DEFINE_ACTION_FUNCTION(DInterBackground, LoadBackground)
{
PARAM_SELF_PROLOGUE(DInterBackground);
PARAM_BOOL(isenterpic);
ACTION_RETURN_BOOL(self->LoadBackground(isenterpic));
}
//====================================================================
//
// made this more generic and configurable through a script
@ -459,7 +536,7 @@ public:
//
//====================================================================
void updateAnimatedBack()
void DInterBackground::updateAnimatedBack()
{
unsigned int i;
@ -489,13 +566,20 @@ public:
}
}
DEFINE_ACTION_FUNCTION(DInterBackground, updateAnimatedBack)
{
PARAM_SELF_PROLOGUE(DInterBackground);
self->updateAnimatedBack();
return 0;
}
//====================================================================
//
// Draws the background including all animations
//
//====================================================================
void drawBackground(int state, bool drawsplat, bool snl_pointeron)
void DInterBackground::drawBackground(int state, bool drawsplat, bool snl_pointeron)
{
unsigned int i;
double animwidth = 320; // For a flat fill or clear background scale animations to 320x200
@ -587,63 +671,26 @@ public:
// Draw only if it points to a valid level on the current screen!
if (v<lnodes.Size()) drawOnLnode(v, &yah[0], yah.Size());
}
}
private:
//====================================================================
//
// Draws the splats and the 'You are here' arrows
//
//====================================================================
int MapToIndex(const char *map)
DEFINE_ACTION_FUNCTION(DInterBackground, drawBackground)
{
unsigned int i;
for (i = 0; i < lnodes.Size(); i++)
{
if (!lnodes[i].Level.CompareNoCase(map))
break;
}
return i;
PARAM_SELF_PROLOGUE(DInterBackground);
PARAM_INT(state);
PARAM_BOOL(splat);
PARAM_BOOL(pointer);
self->drawBackground(state, splat, pointer);
return 0;
}
IMPLEMENT_CLASS(DInterBackground, true, false)
//====================================================================
//
// Draws the splats and the 'You are here' arrows
//
//
//====================================================================
void drawOnLnode(int n, FTexture * c[], int numc)
{
int i;
for (i = 0; i<numc; i++)
{
int left;
int top;
int right;
int bottom;
right = c[i]->GetScaledWidth();
bottom = c[i]->GetScaledHeight();
left = lnodes[n].x - c[i]->GetScaledLeftOffset();
top = lnodes[n].y - c[i]->GetScaledTopOffset();
right += left;
bottom += top;
if (left >= 0 && right < 320 && top >= 0 && bottom < 200)
{
screen->DrawTexture(c[i], lnodes[n].x, lnodes[n].y, DTA_320x200, true, TAG_DONE);
break;
}
}
}
};
struct FPatchInfo
{
@ -715,7 +762,7 @@ public:
//
FInterBackground *bg;
DInterBackground *bg;
int acceleratestage; // used to accelerate or skip a stage
bool playerready[MAXPLAYERS];
int me; // wbs->pnum
@ -2039,14 +2086,15 @@ public:
if (li) lnametexts[1] = li->LookupLevelName();
else lnametexts[1] = "";
bg = new FInterBackground(wbs);
bg = new DInterBackground(wbs);
GC::AddSoftRoot(bg);
noautostartmap = bg->LoadBackground(false);
}
void WI_unloadData ()
{
// [RH] The texture data gets unloaded at pre-map time, so there's nothing to do here
if (bg != nullptr) delete bg;
GC::DelSoftRoot(bg);
bg->Destroy();
bg = nullptr;
return;
}
@ -2149,6 +2197,7 @@ DEFINE_FIELD_X(WBStartStruct, wbstartstruct_t, totaltime);
DEFINE_FIELD_X(WBStartStruct, wbstartstruct_t, pnum);
DEFINE_FIELD_X(WBStartStruct, wbstartstruct_t, plyr);
DEFINE_FIELD(FIntermissionScreen, bg);
DEFINE_FIELD(FIntermissionScreen, acceleratestage);
DEFINE_FIELD(FIntermissionScreen, playerready);
DEFINE_FIELD(FIntermissionScreen, me);

View File

@ -1,4 +1,12 @@
class InterBackground native
{
native InterBackground Create(wbstartstruct wbst);
native bool LoadBackground(bool isenterpic);
native void updateAnimatedBack();
native void drawBackground(int state, bool drawsplat, bool snl_pointeron);
}
struct PatchInfo
{
Font mFont;
@ -60,7 +68,7 @@ struct IntermissionScreen native
const SHOWNEXTLOCDELAY = 4; // in seconds
//FInterBackground *bg;
InterBackground bg;
native int acceleratestage; // used to accelerate or skip a stage
native bool playerready[MAXPLAYERS];
native int me; // wbs.pnum