diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index 16ca73c24..1177928d8 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -42,61 +42,6 @@ This file contains parts of DukeGDX by Alexander Makarov-[M210] (m210-2007@mail. BEGIN_DUKE_NS -struct FireProj -{ - int x, y, z; - int xv, yv, zv; -}; - -static TMap fire; - -static FSerializer& Serialize(FSerializer& arc, const char* key, FireProj& p, FireProj* def) -{ - if (arc.BeginObject(key)) - { - arc("x", p.x) - ("y", p.y) - ("z", p.z) - ("xv", p.xv) - ("yv", p.yv) - ("zv", p.zv) - .EndObject(); - } - return arc; -} - -void SerializeActorGlobals(FSerializer& arc) -{ - if (arc.isWriting() && fire.CountUsed() == 0) return; - bool res = arc.BeginArray("FireProj"); - if (arc.isReading()) - { - fire.Clear(); - if (!res) return; - int length = arc.ArraySize() / 2; - int key; - FireProj value; - - for (int i = 0; i < length; i++) - { - arc(nullptr, key); - Serialize(arc, nullptr, value, nullptr); - fire.Insert(key, value); - } - } - else - { - TMap::Iterator it(fire); - TMap::Pair* pair; - while (it.NextPair(pair)) - { - int k = pair->Key; - Serialize(arc, nullptr, k, nullptr); - Serialize(arc, nullptr, pair->Value, nullptr); - } - } - arc.EndArray(); -} //--------------------------------------------------------------------------- // @@ -1516,22 +1461,21 @@ static bool movefireball(DDukeActor* actor) if (actor->temp_data[0] >= 1 && actor->temp_data[0] < 6) { float siz = 1.0f - (actor->temp_data[0] * 0.2f); - // This still needs work- it stores an actor reference in a general purpose integer field. - int trail = actor->temp_data[1]; + auto trail = actor->temp_actor; auto ball = spawn(actor, FIREBALL); if (ball) { auto spr = ball->s; - actor->temp_data[1] = ball->GetSpriteIndex(); + actor->temp_actor = ball; spr->xvel = s->xvel; spr->yvel = s->yvel; spr->zvel = s->zvel; if (actor->temp_data[0] > 1) { - FireProj* proj = fire.CheckKey(trail); - if (proj != nullptr) + if (trail) { + FireProj* proj = &trail->fproj; spr->x = proj->x; spr->y = proj->y; spr->z = proj->z; @@ -1544,9 +1488,8 @@ static bool movefireball(DDukeActor* actor) spr->cstat = s->cstat; spr->extra = 0; - FireProj proj = { spr->x, spr->y, spr->z, spr->xvel, spr->yvel, spr->zvel }; + ball->fproj = { spr->x, spr->y, spr->z, spr->xvel, spr->yvel, spr->zvel }; - fire.Insert(ball->GetSpriteIndex(), proj); ChangeActorStat(ball, STAT_PROJECTILE); } } diff --git a/source/games/duke/src/savegame.cpp b/source/games/duke/src/savegame.cpp index 53339c5a8..5acc4840e 100644 --- a/source/games/duke/src/savegame.cpp +++ b/source/games/duke/src/savegame.cpp @@ -44,10 +44,24 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms BEGIN_DUKE_NS FSerializer& Serialize(FSerializer& arc, const char* keyname, GameVarValue& w, GameVarValue* def); -void SerializeActorGlobals(FSerializer& arc); void lava_serialize(FSerializer& arc); void SerializeGameVars(FSerializer &arc); +static FSerializer& Serialize(FSerializer& arc, const char* key, FireProj& p, FireProj* def) +{ + if (arc.BeginObject(key)) + { + arc("x", p.x) + ("y", p.y) + ("z", p.z) + ("xv", p.xv) + ("yv", p.yv) + ("zv", p.zv) + .EndObject(); + } + return arc; +} + FSerializer& Serialize(FSerializer& arc, const char* keyname, CraneDef& w, CraneDef* def) { @@ -307,7 +321,9 @@ void DDukeActor::Serialize(FSerializer& arc) .Array("temp_data", temp_data, 6) .Array("temo_wall", temp_walls, 2) ("temp_sect", temp_sect) - ("uservars", uservars); + ("uservars", uservars) + + ("fireproj", fproj); } @@ -432,7 +448,6 @@ void GameInterface::SerializeGameState(FSerializer& arc) .Array("po", po, ud.multimode) .EndObject(); - SerializeActorGlobals(arc); lava_serialize(arc); SerializeGameVars(arc); diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index 31ca7dded..42969eaef 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -21,6 +21,12 @@ struct STATUSBARTYPE bool gotweapon[MAX_WEAPONS]; }; +struct FireProj +{ + int x, y, z; + int xv, yv, zv; +}; + class DDukeActor : public DCoreActor { DECLARE_CLASS(DDukeActor, DCoreActor) @@ -48,6 +54,9 @@ public: TArray uservars; + // Todo: Once we start assigning subclasses to actors, this one needs to be moved to the proper FIREBALL subclass. + FireProj fproj; + DDukeActor() = default; size_t PropagateMark() override; void ClearContent() override