- Exhumed: lighting

This commit is contained in:
Christoph Oelckers 2020-11-30 01:05:17 +01:00
parent 83ba046d04
commit 08d8ba8fe4
2 changed files with 90 additions and 47 deletions

View file

@ -39,8 +39,9 @@ enum
struct Flash struct Flash
{ {
char field_0; char field_0;
short field_1;
int8_t shade; int8_t shade;
short field_1;
int next;
}; };
struct Glow struct Glow
@ -70,12 +71,11 @@ struct Flow
int yacc; int yacc;
}; };
Flash sFlash[kMaxFlashes];
FreeListArray<Flash, kMaxFlashes> sFlash;
Glow sGlow[kMaxGlows]; Glow sGlow[kMaxGlows];
short nNextFlash[kMaxFlashes];
Flicker sFlicker[kMaxFlickers]; Flicker sFlicker[kMaxFlickers];
short nFreeFlash[kMaxFlashes];
Flow sFlowInfo[kMaxFlows]; Flow sFlowInfo[kMaxFlows];
int flickermask[kMaxFlickerMask]; int flickermask[kMaxFlickerMask];
@ -83,7 +83,6 @@ short bTorch = 0;
short nFirstFlash = -1; short nFirstFlash = -1;
short nLastFlash = -1; short nLastFlash = -1;
short nFlashDepth = 2; short nFlashDepth = 2;
short nFlashes;
short nFlowCount; short nFlowCount;
short nFlickerCount; short nFlickerCount;
short nGlowCount; short nGlowCount;
@ -92,38 +91,92 @@ int bDoFlicks = 0;
int bDoGlows = 0; int bDoGlows = 0;
static SavegameHelper sghlighnting("lightning", FSerializer& Serialize(FSerializer& arc, const char* keyname, Flash& w, Flash* def)
SA(sFlash), {
SA(sGlow), if (arc.BeginObject(keyname))
SA(nNextFlash), {
SA(sFlicker), arc("at0", w.field_0)
SA(nFreeFlash), ("shade", w.shade)
SA(sFlowInfo), ("at1", w.field_1)
SA(flickermask), ("next", w.next)
SV(bTorch), .EndObject();
SV(nFirstFlash), }
SV(nLastFlash), return arc;
SV(nFlashDepth), }
SV(nFlashes),
SV(nFlowCount),
SV(nFlickerCount),
SV(nGlowCount),
SV(bDoFlicks),
SV(bDoGlows),
nullptr);
FSerializer& Serialize(FSerializer& arc, const char* keyname, Glow& w, Glow* def)
{
if (arc.BeginObject(keyname))
{
arc("at0", w.field_0)
("at2", w.field_2)
("sector", w.nSector)
("at6", w.field_6)
.EndObject();
}
return arc;
}
FSerializer& Serialize(FSerializer& arc, const char* keyname, Flicker& w, Flicker* def)
{
if (arc.BeginObject(keyname))
{
arc("at0", w.field_0)
("sector", w.nSector)
("at4", w.field_4)
.EndObject();
}
return arc;
}
FSerializer& Serialize(FSerializer& arc, const char* keyname, Flow& w, Flow* def)
{
if (arc.BeginObject(keyname))
{
arc("objindex", w.objindex)
("type", w.type)
("xdelta", w.xdelta)
("ydelta", w.ydelta)
("atc", w.field_C)
("at10", w.field_10)
("xacc", w.xacc)
("yacc", w.yacc)
.EndObject();
}
return arc;
}
void SerializeLighting(FSerializer& arc)
{
if (arc.BeginObject("lighting"))
{
arc("flash", sFlash)
("glowcount", nGlowCount)
.Array("glow", sGlow, nGlowCount)
("flickercount", nFlickerCount)
.Array("flicker", sFlicker, nFlickerCount)
("flowcount", nFlowCount)
.Array("flow", sFlowInfo, nFlowCount)
.Array("flickermask", flickermask, countof(flickermask))
("torch", bTorch)
("firstflash", nFirstFlash)
("lastflash", nLastFlash)
("flashdepth", nFlashDepth)
("doflicks", bDoFlicks)
("doglows", bDoGlows)
.EndObject();
}
}
// done // done
int GrabFlash() int GrabFlash()
{ {
if (nFlashes >= kMaxFlashes) { int nFlash = sFlash.Get();
if (nFlash < 0) {
return -1; return -1;
} }
short nFlash = nFreeFlash[nFlashes]; sFlash[nFlash].next = -1;
nNextFlash[nFlash] = -1;
nFlashes++;
if (nLastFlash <= -1) if (nLastFlash <= -1)
{ {
@ -131,11 +184,10 @@ int GrabFlash()
} }
else else
{ {
nNextFlash[nLastFlash] = nFlash; sFlash[nLastFlash].next = nFlash;
} }
nLastFlash = nFlash; nLastFlash = nFlash;
return nLastFlash; return nLastFlash;
} }
@ -150,13 +202,10 @@ void InitLights()
nGlowCount = 0; nGlowCount = 0;
nFlowCount = 0; nFlowCount = 0;
nFlashes = 0;
bDoFlicks = false; bDoFlicks = false;
bDoGlows = false; bDoGlows = false;
for (i = 0; i < kMaxFlashes; i++) { sFlash.Clear();
nFreeFlash[i] = i;
}
nFirstFlash = -1; nFirstFlash = -1;
nLastFlash = -1; nLastFlash = -1;
@ -348,15 +397,11 @@ void AddFlash(short nSector, int x, int y, int z, int val)
void UndoFlashes() void UndoFlashes()
{ {
if (!nFlashes) {
return;
}
int var_24 = 0; // CHECKME - Watcom error "initializer for variable var_24 may not execute int var_24 = 0; // CHECKME - Watcom error "initializer for variable var_24 may not execute
int edi = -1; int edi = -1;
for (short nFlash = nFirstFlash; nFlash >= 0; nFlash = nNextFlash[nFlash]) for (short nFlash = nFirstFlash; nFlash >= 0; nFlash = sFlash[nFlash].next)
{ {
assert(nFlash < 2000 && nFlash >= 0); assert(nFlash < 2000 && nFlash >= 0);
@ -472,25 +517,21 @@ void UndoFlashes()
loc_1868A: loc_1868A:
nFlashes--;
assert(nFlashes >= 0);
nFreeFlash[nFlashes] = nFlash;
if (edi != -1) if (edi != -1)
{ {
nNextFlash[edi] = nNextFlash[nFlash]; sFlash[edi].next = sFlash[nFlash].next;
} }
if (nFlash == nFirstFlash) if (nFlash == nFirstFlash)
{ {
nFirstFlash = nNextFlash[nFirstFlash]; nFirstFlash = sFlash[nFirstFlash].next;
} }
if (nFlash == nLastFlash) if (nFlash == nLastFlash)
{ {
nLastFlash = edi; nLastFlash = edi;
} }
sFlash.Release(nFlash);
} }
} }

View file

@ -32,6 +32,7 @@ BEGIN_PS_NS
void SerializeAnim(FSerializer& arc); void SerializeAnim(FSerializer& arc);
void SerializeItems(FSerializer& arc); void SerializeItems(FSerializer& arc);
void SerializeMove(FSerializer& arc); void SerializeMove(FSerializer& arc);
void SerializeLighting(FSerializer& arc);
void SerializeObjects(FSerializer& arc); void SerializeObjects(FSerializer& arc);
void SerializePlayer(FSerializer& arc); void SerializePlayer(FSerializer& arc);
void SerializeRa(FSerializer& arc); void SerializeRa(FSerializer& arc);
@ -75,6 +76,7 @@ void GameInterface::SerializeGameState(FSerializer& arc)
SerializeAnim(arc); SerializeAnim(arc);
SerializeItems(arc); SerializeItems(arc);
SerializeMove(arc); SerializeMove(arc);
SerializeLighting(arc);
SerializeObjects(arc); SerializeObjects(arc);
SerializePlayer(arc); SerializePlayer(arc);
SerializeRa(arc); SerializeRa(arc);