From c16115d76c07af35e3d594c07273fd7313a8153a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 20 Jul 2020 20:40:29 +0200 Subject: [PATCH] - first stage of new savegame code. This also refactors the animateptr array into something serializable. This kind of pointer lookup is virtually unrestorable without creating platform locked savegames. --- source/games/duke/src/actors.cpp | 6 +- source/games/duke/src/bowling.cpp | 12 +- source/games/duke/src/funct.h | 4 +- source/games/duke/src/global.h | 10 +- source/games/duke/src/player_r.cpp | 2 +- source/games/duke/src/savegame.cpp | 518 +++++++++++++++++----------- source/games/duke/src/sectors.cpp | 113 +++--- source/games/duke/src/zz_global.cpp | 3 +- 8 files changed, 421 insertions(+), 247 deletions(-) diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index 22e1a4509..c0986b96b 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -3464,7 +3464,7 @@ void handle_se08(int i, bool checkhitag1) } j = 1; } - else j = getanimationgoal(&sc->ceilingz); + else j = getanimationgoal(anim_ceilingz, s->sectnum); if (j >= 0) { @@ -3556,7 +3556,7 @@ void handle_se10(int i, const int* specialtags) { if (specialtags) for (int i = 0; specialtags[i]; i++) { - if (sector[s->sectnum].lotag == specialtags[i] && getanimationgoal(§or[s->sectnum].ceilingz) >= 0) + if (sector[s->sectnum].lotag == specialtags[i] && getanimationgoal(anim_ceilingz, s->sectnum) >= 0) { return; } @@ -4357,7 +4357,7 @@ void handle_se22(int i) auto sc = §or[s->sectnum]; if (t[1]) { - if (getanimationgoal(§or[t[0]].ceilingz) >= 0) + if (getanimationgoal(anim_ceilingz, t[0]) >= 0) sc->ceilingz += sc->extra * 9; else t[1] = 0; } diff --git a/source/games/duke/src/bowling.cpp b/source/games/duke/src/bowling.cpp index 73de3d251..f8b193214 100644 --- a/source/games/duke/src/bowling.cpp +++ b/source/games/duke/src/bowling.cpp @@ -72,13 +72,13 @@ short pinsectorresetdown(short sect) { int vel, j; - j = getanimationgoal(§or[sect].ceilingz); + j = getanimationgoal(anim_ceilingz, sect); if (j == -1) { j = sector[sect].floorz; vel = 64; - setanimation(sect,§or[sect].ceilingz,j,vel); + setanimation(sect, anim_ceilingz, sect, j, vel); return 1; } return 0; @@ -87,14 +87,14 @@ short pinsectorresetdown(short sect) short pinsectorresetup(short sect) { int vel, j; - - j = getanimationgoal(§or[sect].ceilingz); + + j = getanimationgoal(anim_ceilingz, sect); if (j == -1) { - j = sector[nextsectorneighborz(sect,sector[sect].ceilingz,-1,-1)].ceilingz; + j = sector[nextsectorneighborz(sect, sector[sect].ceilingz, -1, -1)].ceilingz; vel = 64; - setanimation(sect,§or[sect].ceilingz,j,vel); + setanimation(sect, anim_ceilingz, sect, j, vel); return 1; } return 0; diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index cc684449b..1762cb969 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -142,10 +142,10 @@ void operateforcefields_common(int s, int low, const std::initializer_list& void operatemasterswitches(int lotag); void operatesectors(int s, int i); void hud_input(int playerNum); -int getanimationgoal(const int* animPtr); +int getanimationgoal(int animtype, int animindex); bool isanearoperator(int lotag); bool isanunderoperator(int lotag); -int setanimation(short animsect, int* animptr, int thegoal, int thevel); +int setanimation(short animsect, int animtype, int animindex, int thegoal, int thevel); void dofurniture(int wallNum, int sectnum, int playerNum); void dotorch(); int hitawall(struct player_struct* pl, int* hitWall); diff --git a/source/games/duke/src/global.h b/source/games/duke/src/global.h index 28df06e5e..c6d951f3a 100644 --- a/source/games/duke/src/global.h +++ b/source/games/duke/src/global.h @@ -109,8 +109,16 @@ extern int mirrorcnt; extern int numplayersprites; extern int spriteqloc; +enum animtype_t +{ + anim_floorz, + anim_ceilingz, + anim_vertexx, + anim_vertexy, +}; extern int16_t animatesect[MAXANIMATES]; -extern int* animateptr[MAXANIMATES]; +extern int16_t animatetarget[MAXANIMATES]; +extern int8_t animatetype[MAXANIMATES]; extern int animategoal[MAXANIMATES]; extern int animatevel[MAXANIMATES]; diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 708232bdb..94d5ba784 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -3666,7 +3666,7 @@ void processinput_r(int snum) if (psectlotag == ST_17_PLATFORM_UP || (isRRRA() && psectlotag == ST_18_ELEVATOR_DOWN)) { int tmp; - tmp = getanimationgoal(§or[p->cursectnum].floorz); + tmp = getanimationgoal(anim_floorz, p->cursectnum); if (tmp >= 0) { if (!S_CheckSoundPlaying(p->i, 432)) diff --git a/source/games/duke/src/savegame.cpp b/source/games/duke/src/savegame.cpp index 342c11ca9..27b665044 100644 --- a/source/games/duke/src/savegame.cpp +++ b/source/games/duke/src/savegame.cpp @@ -33,7 +33,227 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au) BEGIN_DUKE_NS +FSerializer& Serialize(FSerializer& arc, const char* keyname, animwalltype& w, animwalltype* def) +{ + if (arc.BeginObject(keyname)) + { + arc("wallnum", w.wallnum) + ("tag", w.tag) + .EndObject(); + } + return arc; +} +FSerializer& Serialize(FSerializer& arc, const char* keyname, player_orig& w, player_orig* def) +{ + if (arc.BeginObject(keyname)) + { + arc("ox", w.ox) + ("oy", w.oy) + ("oz", w.oz) + ("oa", w.oa) + ("os", w.os) + .EndObject(); + } + return arc; +} + +FSerializer& Serialize(FSerializer& arc, const char* keyname, player_struct& w, player_struct* def) +{ + if (arc.BeginObject(keyname)) + { + arc("posx", w.posx) + ("posy", w.posy) + ("posz", w.posz) + ("q16ang", w.q16ang) + ("q16horiz", w.q16horiz) + ("q16horizoff", w.q16horizoff) + ("q16rotscrnang", w.q16rotscrnang) + ("q16look_ang", w.q16look_ang) + ("one_eighty_count", w.one_eighty_count) + ("gotweapon", w.gotweapon) + ("palette", w.palette) + ("pals", w.pals) + ("fricx", w.fric.x) + ("fricy", w.fric.y) + ("zoom", w.zoom) + ("exitx", w.exitx) + ("exity", w.exity) + ("numloogs", w.numloogs) + ("loogcnt", w.loogcnt) + .Array("loogiex", w.loogiex, w.numloogs) + .Array("loogiey", w.loogiey, w.numloogs) + ("bobposx", w.bobposx) + ("bobposy", w.bobposy) + ("pyoff", w.pyoff) + ("posxv", w.posxv) + ("posyv", w.posyv) + ("poszv", w.poszv) + ("last_pissed_time", w.last_pissed_time) + ("truefz", w.truefz) + ("truecz", w.truecz) + ("player_par", w.player_par) + ("visibility", w.visibility) + ("bobcounter", w.bobcounter) + ("weapon_sway", w.weapon_sway) + ("pals_time", w.pals_time) + ("randomflamex", w.randomflamex) + ("crack_time", w.crack_time) + ("aim.mode", w.aim_mode) + ("auto_aim", w.auto_aim) + ("weaponswitch", w.weaponswitch) + ("angvel", w.angvel) + ("cursectnum", w.cursectnum) + ("last_extra", w.last_extra) + ("subweapon", w.subweapon) + .Array("ammo_count", w.ammo_amount, MAX_WEAPONS) + ("wackedbyactor", w.wackedbyactor) + ("frag", w.frag) + ("fraggedself", w.fraggedself) + ("curr_weapon", w.curr_weapon) + ("last_weapon", w.last_weapon) + ("tipincs", w.tipincs) + ("wantweaponfire", w.wantweaponfire) + ("holoduke_amount", w.holoduke_amount) + ("newowner", w.newowner) + ("hurt_delay", w.hurt_delay) + ("hbomb_hold_delay", w.hbomb_hold_delay) + ("jumping_counter", w.jumping_counter) + ("airleft", w.airleft) + ("knee_incs", w.knee_incs) + ("access_incs", w.access_incs) + ("ftq", w.ftq) + ("access_wallnum", w.access_wallnum) + ("access_spritenum", w.access_spritenum) + ("kickback_pic", w.kickback_pic) + ("got_access", w.got_access) + ("weapon_ang", w.weapon_ang) + ("firstaid_amount", w.firstaid_amount) + ("somethingonplayer", w.somethingonplayer) + ("on_crane", w.on_crane) + ("i", w.i) + ("one_parallax_sectnum", w.one_parallax_sectnum) + ("over_shoulder_on", w.over_shoulder_on) + ("random_club_frame", w.random_club_frame) + ("fist_incs", w.fist_incs) + ("dummyplayersprite", w.dummyplayersprite) + ("extra_extra8", w.extra_extra8) + ("quick_kick", w.quick_kick) + ("heat_amount", w.heat_amount) + ("actorsqu", w.actorsqu) + ("timebeforeexit", w.timebeforeexit) + ("customexitsound", w.customexitsound) + ("weapreccnt", w.weapreccnt) + .Array("weaprecs", w.weaprecs, w.weapreccnt) + ("interface_toggle_flag", w.interface_toggle_flag) + ("dead_flag", w.dead_flag) + ("show_empty_weapon", w.show_empty_weapon) + ("scuba_amount", w.scuba_amount) + ("jetpack_amount", w.jetpack_amount) + ("steroids_amount", w.steroids_amount) + ("shield_amount", w.shield_amount) + ("holoduke_on", w.holoduke_on) + ("pycount", w.pycount) + ("weapon_pos", w.weapon_pos) + ("frag_ps", w.frag_ps) + ("transporter_hold", w.transporter_hold) + ("last_full_weapon", w.last_full_weapon) + ("footprintshade", w.footprintshade) + ("boot_amount", w.boot_amount) + ("scream_voice", w.scream_voice) + ("gm", w.gm) + ("on_warping_sector", w.on_warping_sector) + ("footprintcount", w.footprintcount) + ("hbomb_on", w.hbomb_on) + ("jumping_toggle", w.jumping_toggle) + ("rapid_fire_hold", w.rapid_fire_hold) + ("on_ground", w.on_ground) + .Array("name", w.name, 32) + ("inven_icon", w.inven_icon) + ("buttonpalette", w.buttonpalette) + ("jetpack_on", w.jetpack_on) + ("spritebridge", w.spritebridge) + ("lastrandomspot", w.lastrandomspot) + ("scuba_on", w.scuba_on) + ("footprintpal", w.footprintpal) + ("heat_on", w.heat_on) + ("holster_weapon", w.holster_weapon) + ("falling_counter", w.falling_counter) + ("refresh_inventory", w.refresh_inventory) + ("toggle_key_flag", w.toggle_key_flag) + ("knuckle_incs", w.knuckle_incs) + ("walking_snd_toggle", w.walking_snd_toggle) + ("palookup", w.palookup) + ("hard_landing", w.hard_landing) + ("return_to_center", w.return_to_center) + ("max_secret_rooms", w.max_secret_rooms) + ("secret_rooms", w.secret_rooms) + ("max_actors_killed", w.max_actors_killed) + ("actors_killed", w.actors_killed) + // RR from here on + ("stairs", w.stairs) + ("detonate_count", w.detonate_count) + ("noise_x", w.noise_x) + ("noise_y", w.noise_y) + ("noise_radius", w.noise_radius) + ("drink_timer", w.drink_timer) + ("eat_timer", w.eat_timer) + ("slotwin", w.SlotWin) + ("recoil", w.recoil) + ("detonate_time", w.detonate_time) + ("yehaa_timer", w.yehaa_timer) + ("drink_amt", w.drink_amt) + ("eat", w.eat) + ("drunkang", w.drunkang) + ("eatang", w.eatang) + .Array("shotgun_state", w.shotgun_state, 2) + ("donoise", w.donoise) + .Array("keys", w.keys, 5) + // RRRA from here on + ("drug_aspect", w.drug_aspect) + ("drug_timer", w.drug_timer) + ("seasick", w.SeaSick) + ("mamaend", w.MamaEnd) + ("motospeed", w.MotoSpeed) + ("moto_drink", w.moto_drink) + ("tiltstatus", w.TiltStatus) + ("vbumpnow", w.VBumpNow) + ("vbumptarget", w.VBumpTarget) + ("turbcount", w.TurbCount) + .Array("drug_stat", w.drug_stat, 3) + ("drugmode", w.DrugMode) + ("lotag800kill", w.lotag800kill) + ("sea_sick_stat", w.sea_sick_stat) + ("hurt_delay2", w.hurt_delay2) + ("nocheat", w.nocheat) + ("onmotorcycle", w.OnMotorcycle) + ("onboat", w.OnBoat) + ("moto_underwater", w.moto_underwater) + ("notonwater", w.NotOnWater) + ("motoonground", w.MotoOnGround) + ("moto_do_bump", w.moto_do_bump) + ("moto_bump_fast", w.moto_bump_fast) + ("moto_on_oil", w.moto_on_oil) + ("moto_on_mud", w.moto_on_mud) + ("crouch_toggle", w.crouch_toggle) + .EndObject(); + + w.invdisptime = 0; + w.oq16ang = w.q16ang; + w.oq16horiz = w.q16horiz; + w.oq16horizoff = w.q16horizoff; + w.oq16rotscrnang = w.q16rotscrnang; + w.oposx = w.posx; + w.oposy = w.posy; + w.oposz = w.posz; + w.opyoff = w.pyoff; + w.horizAngleAdjust = 0; + w.horizSkew = 0; + w.lookLeft = false; + w.lookRight = false; + } + return arc; +} FSerializer& Serialize(FSerializer& arc, const char* keyname, weaponhit& w, weaponhit* def) { @@ -64,199 +284,132 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, weaponhit& w, weap } -int SerializeGlobals(FSerializer &arc) +void SerializeGlobals(FSerializer& arc) { + if (arc.isReading()) + { + memset(sectorextra, 0, sizeof(sectorextra)); + memset(spriteextra, 0, sizeof(spriteextra)); + memset(shadedsector, 0, sizeof(shadedsector)); + memset(geosectorwarp, -1, sizeof(geosectorwarp)); + memset(geosectorwarp2, -1, sizeof(geosectorwarp2)); + memset(ambienthitag, -1, sizeof(ambienthitag)); + memset(ambientlotag, -1, sizeof(ambientlotag)); + } if (arc.BeginObject("globals")) { - arc("skill", ud.player_skill); - ud.m_player_skill = ud.player_skill; - arc.Array("spriteextra", spriteextra, MAXSPRITES) + arc("multimode", ud.multimode); + if (ud.multimode > 1) arc.Array("frags", &frags[0][0], MAXPLAYERS * MAXPLAYERS); + arc("skill", ud.player_skill) + + ("from_bonus", ud.from_bonus) + ("secretlevel", ud.secretlevel) + ("respawn_monsters", ud.respawn_monsters) + ("respawn_items", ud.respawn_items) + ("respawn_inventory", ud.respawn_inventory) + ("god", ud.god) + //("auto_run", ud.auto_run) + ("monsters_off", ud.monsters_off) + ("last_level", ud.last_level) + ("eog", ud.eog) + ("coop", ud.coop) + ("marker", ud.marker) + ("ffire", ud.ffire) + + .Array("spriteextra", spriteextra, MAXSPRITES) .Array("weaponhit", hittype, MAXSPRITES) .Array("sectorextra", sectorextra, numsectors) ("rtsplaying", rtsplaying) ("tempwallptr", tempwallptr) ("sound445done", sound445done) ("leveltexttime", levelTextTime) + .Array("players", ps, ud.multimode) + ("spriteqamount", spriteqamount) + .Array("shadedsector", shadedsector, numsectors) + ("lastvisinc", lastvisinc) + ("numanimwalls", numanimwalls) + .Array("animwall", animwall, numanimwalls) + ("camsprite", camsprite) + ("earthquaketime", earthquaketime) + ("freezerhurtowner", freezerhurtowner) + ("global_random", global_random) + ("impact_damage", impact_damage) + ("numplayersprites", numplayersprites) + ("spriteqloc", spriteqloc) + ("animatecnt", animatecnt) -/* - extern player_struct ps[MAXPLAYERS]; - extern int spriteqamount; - extern uint8_t shadedsector[MAXSECTORS]; - extern int lastvisinc; - extern animwalltype animwall[MAXANIMWALLS]; - extern int numanimwalls; - extern int animatecnt; - extern int numclouds; - extern int camsprite; - extern int numcyclers; - extern int earthquaketime; - extern int freezerhurtowner; - extern int global_random; - extern int impact_damage; - extern int mirrorcnt; - extern int numplayersprites; - extern int spriteqloc; + .Array("animatesect", animatesect, animatecnt) + .Array("animatetype", animatetype, animatecnt) + .Array("animatetarget", animatetarget, animatecnt) + .Array("animategoal", animategoal, animatecnt) + .Array("animatevel", animatevel, animatecnt) - extern int16_t animatesect[MAXANIMATES]; - extern int* animateptr[MAXANIMATES]; - extern int animategoal[MAXANIMATES]; - extern int animatevel[MAXANIMATES]; + ("numclouds", numclouds) + ("cloudx", cloudx) + ("cloudy", cloudy) + ("cloudtotalclock", cloudtotalclock) + .Array("clouds", clouds, numclouds) - extern int16_t clouds[256]; - extern int16_t cloudx; - extern int16_t cloudy; - extern ClockTicks cloudtotalclock; + .Array("spriteq", spriteq, 1024) + ("numcyclers", numcyclers) + .Array("cyclers", &cyclers[0][0], 6 * numcyclers) + ("mirrorcnt", mirrorcnt) + .Array("mirrorsector", mirrorsector, mirrorcnt) + .Array("mirrorwall", mirrorwall, mirrorcnt) + ("lockclock", lockclock) + ("wupass", wupass) + ("chickenplant", chickenplant) + ("thunderon", thunderon) + ("ufospawn", ufospawn) + ("ufocnt", ufocnt) + ("hulkspawn", hulkspawn) + ("lastlevel", lastlevel) + ("geocnt", geocnt) + .Array("geosectorwarp", geosectorwarp, geocnt) + .Array("geosectorwarp2", geosectorwarp2, geocnt) + .Array("geosector", geosector, geocnt) + .Array("geox", geox, geocnt) + .Array("geoy", geoy, geocnt) + .Array("geox2", geox2, geocnt) + .Array("geoy2", geoy2, geocnt) + ("ambientfx", ambientfx) + .Array("ambientlotag", ambientlotag, ambientfx) + .Array("ambienthitag", ambienthitag, ambientfx) + .Array("msx", msx, MAXANIMPOINTS) + .Array("msy", msy, MAXANIMPOINTS) + ("windtime", WindTime) + ("winddir", WindDir) + ("fakebubba_spawn", fakebubba_spawn) + ("mamaspawn_count", mamaspawn_count) + ("banjosound", banjosound) + ("belltime", BellTime) + ("bellsprite", BellSprite) + ("enemysizecheat", enemysizecheat) + ("ufospawnsminion", ufospawnsminion) + ("pistonsound", pistonsound) + ("chickenphase", chickenphase) + ("RRRA_ExitedLevel", RRRA_ExitedLevel) + ("fogactive", fogactive) + ("everyothertime", everyothertime) + .Array("po", po, ud.multimode) + .EndObject(); - extern int16_t spriteq[1024]; - extern int16_t cyclers[MAXCYCLERS][6]; - extern int16_t mirrorsector[64]; - extern int16_t mirrorwall[64]; - - extern ClockTicks lockclock; - - extern int wupass; - extern int chickenplant; - extern int thunderon; - extern int ufospawn; - extern int ufocnt; - extern int hulkspawn; - extern int lastlevel; - - extern int geosectorwarp[MAXGEOSECTORS]; - extern int geosectorwarp2[MAXGEOSECTORS]; - extern int geosector[MAXGEOSECTORS]; - extern int geox[MAXGEOSECTORS]; - extern int geoy[MAXGEOSECTORS]; - extern int geox2[MAXGEOSECTORS]; - extern int geoy2[MAXGEOSECTORS]; - extern int geocnt; - - extern short ambientlotag[64]; - extern short ambienthitag[64]; - extern unsigned ambientfx; - extern int msx[MAXANIMPOINTS], msy[MAXANIMPOINTS]; - extern int WindTime, WindDir; - extern short fakebubba_spawn, mamaspawn_count, banjosound; - extern short BellTime, BellSprite; - extern uint8_t enemysizecheat, ufospawnsminion, pistonsound, chickenphase, RRRA_ExitedLevel, fogactive; - extern uint32_t everyothertime; - extern player_orig po[MAXPLAYERS]; - - extern uint16_t frags[MAXPLAYERS][MAXPLAYERS]; - -*/ - - if (kdfread(&numcyclers, sizeof(numcyclers), 1, fil) != 1) goto corrupt; - if (kdfread(&cyclers[0][0], 12, MAXCYCLERS, fil) != MAXCYCLERS) goto corrupt; - if (kdfread(ps, sizeof(ps), 1, fil) != 1) goto corrupt; - if (kdfread(po, sizeof(po), 1, fil) != 1) goto corrupt; - if (kdfread(&numanimwalls, sizeof(numanimwalls), 1, fil) != 1) goto corrupt; - if (kdfread(&animwall, sizeof(animwall), 1, fil) != 1) goto corrupt; - if (kdfread(&msx[0], sizeof(int), sizeof(msx) / sizeof(int), fil) != sizeof(msx) / sizeof(int)) goto corrupt; - if (kdfread(&msy[0], sizeof(int), sizeof(msy) / sizeof(int), fil) != sizeof(msy) / sizeof(int)) goto corrupt; - if (kdfread((short*)&spriteqloc, sizeof(short), 1, fil) != 1) goto corrupt; - if (kdfread((short*)&spriteqamount, sizeof(short), 1, fil) != 1) goto corrupt; - if (kdfread((short*)&spriteq[0], sizeof(short), spriteqamount, fil) != spriteqamount) goto corrupt; - if (kdfread(&mirrorcnt, sizeof(short), 1, fil) != 1) goto corrupt; - if (kdfread(&mirrorwall[0], sizeof(short), 64, fil) != 64) goto corrupt; - if (kdfread(&mirrorsector[0], sizeof(short), 64, fil) != 64) goto corrupt; - if (kdfread(&show2dsector[0], sizeof(char), MAXSECTORS >> 3, fil) != (MAXSECTORS >> 3)) goto corrupt; - if (kdfread(&actortype[0], sizeof(char), MAXTILES, fil) != MAXTILES) goto corrupt; - - if (kdfread(&numclouds, sizeof(numclouds), 1, fil) != 1) goto corrupt; - if (kdfread(&clouds[0], sizeof(short) << 7, 1, fil) != 1) goto corrupt; - if (kdfread(&cloudx[0], sizeof(short) << 7, 1, fil) != 1) goto corrupt; - if (kdfread(&cloudy[0], sizeof(short) << 7, 1, fil) != 1) goto corrupt; - - if (kdfread(&script[0], 4, MAXSCRIPTSIZE, fil) != MAXSCRIPTSIZE) goto corrupt; - - if (kdfread(&ptrbuf[0], 4, MAXTILES, fil) != MAXTILES) goto corrupt; - for (i = 0; i < MAXTILES; i++) - if (ptrbuf[i]) - { - actorscrptr[i] = (int*)((intptr_t)&script[0] + ptrbuf[i]); - } - - if (kdfread(&lockclock, sizeof(lockclock), 1, fil) != 1) goto corrupt; - if (kdfread(&pskybits, sizeof(pskybits), 1, fil) != 1) goto corrupt; - if (kdfread(&pskyoff[0], sizeof(pskyoff[0]), MAXPSKYTILES, fil) != MAXPSKYTILES) goto corrupt; - - if (kdfread(&animatecnt, sizeof(animatecnt), 1, fil) != 1) goto corrupt; - if (kdfread(&animatesect[0], 2, MAXANIMATES, fil) != MAXANIMATES) goto corrupt; - if (kdfread(&ptrbuf[0], 4, MAXANIMATES, fil) != MAXANIMATES) goto corrupt; - for (i = animatecnt - 1; i >= 0; i--) animateptr[i] = (int*)((intptr_t)§or[0] + ptrbuf[i]); - if (kdfread(&animategoal[0], 4, MAXANIMATES, fil) != MAXANIMATES) goto corrupt; - if (kdfread(&animatevel[0], 4, MAXANIMATES, fil) != MAXANIMATES) goto corrupt; - - if (kdfread(&earthquaketime, sizeof(earthquaketime), 1, fil) != 1) goto corrupt; - if (kdfread(&ud.from_bonus, sizeof(ud.from_bonus), 1, fil) != 1) goto corrupt; - if (kdfread(&ud.secretlevel, sizeof(ud.secretlevel), 1, fil) != 1) goto corrupt; - if (kdfread(&ud.respawn_monsters, sizeof(ud.respawn_monsters), 1, fil) != 1) goto corrupt; + ud.m_player_skill = ud.player_skill; ud.m_respawn_monsters = ud.respawn_monsters; - if (kdfread(&ud.respawn_items, sizeof(ud.respawn_items), 1, fil) != 1) goto corrupt; ud.m_respawn_items = ud.respawn_items; - if (kdfread(&ud.respawn_inventory, sizeof(ud.respawn_inventory), 1, fil) != 1) goto corrupt; ud.m_respawn_inventory = ud.respawn_inventory; - - if (kdfread(&ud.god, sizeof(ud.god), 1, fil) != 1) goto corrupt; - if (kdfread(&ud.auto_run, sizeof(ud.auto_run), 1, fil) != 1) goto corrupt; - if (kdfread(&ud.crosshair, sizeof(ud.crosshair), 1, fil) != 1) goto corrupt; - if (kdfread(&ud.monsters_off, sizeof(ud.monsters_off), 1, fil) != 1) goto corrupt; ud.m_monsters_off = ud.monsters_off; - if (kdfread(&ud.last_level, sizeof(ud.last_level), 1, fil) != 1) goto corrupt; - if (kdfread(&ud.eog, sizeof(ud.eog), 1, fil) != 1) goto corrupt; - - if (kdfread(&ud.coop, sizeof(ud.coop), 1, fil) != 1) goto corrupt; ud.m_coop = ud.coop; - if (kdfread(&ud.marker, sizeof(ud.marker), 1, fil) != 1) goto corrupt; ud.m_marker = ud.marker; - if (kdfread(&ud.ffire, sizeof(ud.ffire), 1, fil) != 1) goto corrupt; ud.m_ffire = ud.ffire; - if (kdfread(&camsprite, sizeof(camsprite), 1, fil) != 1) goto corrupt; - if (kdfread(&connecthead, sizeof(connecthead), 1, fil) != 1) goto corrupt; - if (kdfread(connectpoint2, sizeof(connectpoint2), 1, fil) != 1) goto corrupt; - if (kdfread(&numplayersprites, sizeof(numplayersprites), 1, fil) != 1) goto corrupt; - if (kdfread((short*)&frags[0][0], sizeof(frags), 1, fil) != 1) goto corrupt; - - if (kdfread(&randomseed, sizeof(randomseed), 1, fil) != 1) goto corrupt; - if (kdfread(&global_random, sizeof(global_random), 1, fil) != 1) goto corrupt; - if (kdfread(¶llaxyscale, sizeof(parallaxyscale), 1, fil) != 1) goto corrupt; - - kdfread(&shadedsector[0], sizeof(shadedsector[0]), MAXSECTORS, fil); - kdfread(&ambientfx, sizeof(ambientfx), 1, fil); - kdfread(&ambienthitag[0], sizeof(ambienthitag[0]), 64, fil); - kdfread(&ambientlotag[0], sizeof(ambientlotag[0]), 64, fil); - kdfread(&ambientsprite[0], sizeof(ambientsprite[0]), 64, fil); - kdfread(&ufospawn, sizeof(ufospawn), 1, fil); - kdfread(&ufocnt, sizeof(ufocnt), 1, fil); - kdfread(&hulkspawn, sizeof(hulkspawn), 1, fil); - kdfread(&geosector[0], sizeof(geosector[0]), 64, fil); - kdfread(&geosectorwarp[0], sizeof(geosectorwarp[0]), 64, fil); - kdfread(&geox[0], sizeof(geox[0]), 64, fil); - kdfread(&geoy[0], sizeof(geoy[0]), 64, fil); - kdfread(&geoz[0], sizeof(geoz[0]), 64, fil); - kdfread(&geosectorwarp2[0], sizeof(geosectorwarp2[0]), 64, fil); - kdfread(&geox2[0], sizeof(geox2[0]), 64, fil); - kdfread(&geoy2[0], sizeof(geoy2[0]), 64, fil); - kdfread(&geoz2[0], sizeof(geoz2[0]), 64, fil); - kdfread(&geocnt, sizeof(geocnt), 1, fil); -#ifdef RRRA - kdfread(&WindTime, 4, 1, fil); - kdfread(&WindDir, 4, 1, fil); - kdfread(&word_119BD8, 2, 1, fil); - kdfread(&word_119BDA, 2, 1, fil); - if (ps[myconnectindex].fogtype > 1) - sub_86730(ps[myconnectindex].fogtype); - else if (ps[myconnectindex].fogtype == 0) - sub_86730(0); -#else - tilesizx[0] = tilesizy[0] = 0; -#endif - kclose(fil); } +} +#if 0 + if (arc.isReading()) + { if(ps[myconnectindex].over_shoulder_on != 0) { cameradist = 0; @@ -285,26 +438,6 @@ int SerializeGlobals(FSerializer &arc) FX_SetReverb(0); - if(ud.lockout == 0) - { - for(x=0;x= 0 ) - wall[animwall[x].wallnum].picnum = wall[animwall[x].wallnum].extra; - } - else - { - for(x=0;x=0;i--) bakipos[i] = *curipos[i]; for(i = animatecnt-1;i>=0;i--) - setinterpolation(animateptr[i]); + setinterpolation(animateptr(i)); show_shareware = 0; everyothertime = 0; @@ -381,7 +514,7 @@ int saveplayer(signed char spot) int ptrbuf[MAXTILES]; assert(MAXTILES > MAXANIMATES); - + strcpy(fn, "game0.sav"); strcpy(mpfn, "gameA_00.sav"); @@ -483,7 +616,6 @@ int saveplayer(signed char spot) dfwrite(&pskyoff[0],sizeof(pskyoff[0]),MAXPSKYTILES,fil); dfwrite(&animatecnt,sizeof(animatecnt),1,fil); dfwrite(&animatesect[0],2,MAXANIMATES,fil); - for(i = animatecnt-1;i>=0;i--) ptrbuf[i] = (int)((intptr_t)animateptr[i] - (intptr_t)§or[0]); dfwrite(&ptrbuf[0],4,MAXANIMATES,fil); dfwrite(&animategoal[0],4,MAXANIMATES,fil); dfwrite(&animatevel[0],4,MAXANIMATES,fil); @@ -529,5 +661,5 @@ int saveplayer(signed char spot) return(0); } - +#endif END_DUKE_NS diff --git a/source/games/duke/src/sectors.cpp b/source/games/duke/src/sectors.cpp index c7b11db64..81f3a786d 100644 --- a/source/games/duke/src/sectors.cpp +++ b/source/games/duke/src/sectors.cpp @@ -272,27 +272,58 @@ int findotherplayer(int p, int* d) // //--------------------------------------------------------------------------- +int* animateptr(int type, int index) +{ + static int scratch; + switch (type) + { + case anim_floorz: + return §or[index].floorz; + case anim_ceilingz: + return §or[index].ceilingz; + case anim_vertexx: + return &wall[index].x; + case anim_vertexy: + return &wall[index].y; + default: + assert(false); + return &scratch; + } +} + +int* animateptr(int i) +{ + return animateptr(animatetype[i], animatetarget[i]); +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + void doanimations(void) { int i, j, a, p, v, dasect; for (i = animatecnt - 1; i >= 0; i--) { - a = *animateptr[i]; + a = *animateptr(i); v = animatevel[i] * TICSPERFRAME; dasect = animatesect[i]; if (a == animategoal[i]) { - stopinterpolation(animateptr[i]); + stopinterpolation(animateptr(i)); animatecnt--; - animateptr[i] = animateptr[animatecnt]; + animatetype[i] = animatetype[animatecnt]; + animatetarget[i] = animatetarget[animatecnt]; animategoal[i] = animategoal[animatecnt]; animatevel[i] = animatevel[animatecnt]; animatesect[i] = animatesect[animatecnt]; if (sector[animatesect[i]].lotag == ST_18_ELEVATOR_DOWN || sector[animatesect[i]].lotag == ST_19_ELEVATOR_UP) - if (animateptr[i] == §or[animatesect[i]].ceilingz) + if (animatetype[i] == anim_ceilingz) continue; if ((sector[dasect].lotag & 0xff) != ST_22_SPLITTING_DOOR) @@ -304,7 +335,7 @@ void doanimations(void) if (v > 0) { a = min(a + v, animategoal[i]); } else { a = max(a + v, animategoal[i]); } - if (animateptr[i] == §or[animatesect[i]].floorz) + if (animatetype[i] == anim_floorz) { for (p = connecthead; p >= 0; p = connectpoint2[p]) if (ps[p].cursectnum == dasect) @@ -324,7 +355,7 @@ void doanimations(void) } } - *animateptr[i] = a; + *animateptr(i) = a; } } @@ -334,13 +365,13 @@ void doanimations(void) // //--------------------------------------------------------------------------- -int getanimationgoal(const int* animptr) +int getanimationgoal(int animtype, int animtarget) { int i, j; j = -1; for (i = animatecnt - 1; i >= 0; i--) - if (animptr == animateptr[i]) + if (animtype == animatetype[i] && animtarget == animatetarget[i]) { j = i; break; @@ -354,7 +385,7 @@ int getanimationgoal(const int* animptr) // //--------------------------------------------------------------------------- -int setanimation(short animsect, int* animptr, int thegoal, int thevel) +int setanimation(short animsect, int animtype, int animtarget, int thegoal, int thevel) { int i, j; @@ -363,14 +394,16 @@ int setanimation(short animsect, int* animptr, int thegoal, int thevel) j = animatecnt; for (i = 0; i < animatecnt; i++) - if (animptr == animateptr[i]) + if (animtype == animatetype[i] && animtarget == animatetarget[i]) { j = i; break; } + auto animptr = animateptr(animtype, animtarget); animatesect[j] = animsect; - animateptr[j] = animptr; + animatetype[j] = animtype; + animatetarget[j] = animtarget; animategoal[j] = thegoal; if (thegoal >= *animptr) animatevel[j] = thevel; @@ -466,8 +499,8 @@ void operatesectors(int sn, int ii) endwall = startwall + sptr->wallnum; for (j = startwall; j < endwall; j++) { - setanimation(sn, &wall[j].x, wall[j].x + 1024, 4); - setanimation(sn, &wall[wall[j].nextwall].x, wall[wall[j].nextwall].x + 1024, 4); + setanimation(sn, anim_vertexx, j, wall[j].x + 1024, 4); + setanimation(sn, anim_vertexx, wall[j].nextwall, wall[wall[j].nextwall].x + 1024, 4); } break; @@ -491,7 +524,7 @@ void operatesectors(int sn, int ii) break; case ST_26_SPLITTING_ST_DOOR: //The split doors - i = getanimationgoal(&sptr->ceilingz); + i = getanimationgoal(anim_ceilingz, sn); if (i == -1) //if the door has stopped { haltsoundhack = 1; @@ -551,18 +584,18 @@ void operatesectors(int sn, int ii) { dax2 = wall[wall[wall[wallfind[j]].point2].point2].x; dax2 -= wall[wall[wallfind[j]].point2].x; - setanimation(sn, &wall[wallfind[j]].x, wall[wallfind[j]].x + dax2, sp); - setanimation(sn, &wall[i].x, wall[i].x + dax2, sp); - setanimation(sn, &wall[wall[wallfind[j]].point2].x, wall[wall[wallfind[j]].point2].x + dax2, sp); + setanimation(sn, anim_vertexx, wallfind[j], wall[wallfind[j]].x + dax2, sp); + setanimation(sn, anim_vertexx, i, wall[i].x + dax2, sp); + setanimation(sn, anim_vertexx, wall[wallfind[j]].point2, wall[wall[wallfind[j]].point2].x + dax2, sp); callsound(sn, ii); } else if (day2 != 0) { day2 = wall[wall[wall[wallfind[j]].point2].point2].y; day2 -= wall[wall[wallfind[j]].point2].y; - setanimation(sn, &wall[wallfind[j]].y, wall[wallfind[j]].y + day2, sp); - setanimation(sn, &wall[i].y, wall[i].y + day2, sp); - setanimation(sn, &wall[wall[wallfind[j]].point2].y, wall[wall[wallfind[j]].point2].y + day2, sp); + setanimation(sn, anim_vertexy, wallfind[j], wall[wallfind[j]].y + day2, sp); + setanimation(sn, anim_vertexy, i, wall[i].y + day2, sp); + setanimation(sn, anim_vertexy, wall[wallfind[j]].point2, wall[wall[wallfind[j]].point2].y + day2, sp); callsound(sn, ii); } } @@ -573,16 +606,16 @@ void operatesectors(int sn, int ii) day2 = ((wall[i].y + wall[wall[wallfind[j]].point2].y) >> 1) - wall[wallfind[j]].y; if (dax2 != 0) { - setanimation(sn, &wall[wallfind[j]].x, dax, sp); - setanimation(sn, &wall[i].x, dax + dax2, sp); - setanimation(sn, &wall[wall[wallfind[j]].point2].x, dax + dax2, sp); + setanimation(sn, anim_vertexx, wallfind[j], dax, sp); + setanimation(sn, anim_vertexx, i, dax + dax2, sp); + setanimation(sn, anim_vertexx, wall[wallfind[j]].point2, dax + dax2, sp); callsound(sn, ii); } else if (day2 != 0) { - setanimation(sn, &wall[wallfind[j]].y, day, sp); - setanimation(sn, &wall[i].y, day + day2, sp); - setanimation(sn, &wall[wall[wallfind[j]].point2].y, day + day2, sp); + setanimation(sn, anim_vertexy, wallfind[j], day, sp); + setanimation(sn, anim_vertexy, i, day + day2, sp); + setanimation(sn, anim_vertexy, wall[wallfind[j]].point2, day + day2, sp); callsound(sn, ii); } } @@ -624,7 +657,7 @@ void operatesectors(int sn, int ii) case ST_16_PLATFORM_DOWN: case ST_17_PLATFORM_UP: - i = getanimationgoal(&sptr->floorz); + i = getanimationgoal(anim_floorz, sn); if (i == -1) { @@ -634,12 +667,12 @@ void operatesectors(int sn, int ii) i = nextsectorneighborz(sn, sptr->floorz, 1, -1); if (i == -1) return; j = sector[i].floorz; - setanimation(sn, &sptr->floorz, j, sptr->extra); + setanimation(sn, anim_floorz, sn, j, sptr->extra); } else { j = sector[i].floorz; - setanimation(sn, &sptr->floorz, j, sptr->extra); + setanimation(sn, anim_floorz, sn, j, sptr->extra); } callsound(sn, ii); } @@ -649,7 +682,7 @@ void operatesectors(int sn, int ii) case ST_18_ELEVATOR_DOWN: case ST_19_ELEVATOR_UP: - i = getanimationgoal(&sptr->floorz); + i = getanimationgoal(anim_floorz, sn); if (i == -1) { @@ -659,8 +692,8 @@ void operatesectors(int sn, int ii) j = sector[i].floorz; q = sptr->extra; l = sptr->ceilingz - sptr->floorz; - setanimation(sn, &sptr->floorz, j, q); - setanimation(sn, &sptr->ceilingz, j + l, q); + setanimation(sn, anim_floorz, sn, j, q); + setanimation(sn, anim_ceilingz, sn, j + l, q); callsound(sn, ii); } return; @@ -688,7 +721,7 @@ void operatesectors(int sn, int ii) sptr->lotag ^= 0x8000; - setanimation(sn, &sptr->ceilingz, j, sptr->extra); + setanimation(sn, anim_ceilingz, sn, j, sptr->extra); callsound(sn, ii); @@ -726,13 +759,13 @@ void operatesectors(int sn, int ii) sptr->lotag ^= 0x8000; - setanimation(sn, &sptr->ceilingz, j, sptr->extra); + setanimation(sn, anim_ceilingz, sn, j, sptr->extra); callsound(sn, ii); return; case ST_21_FLOOR_DOOR: - i = getanimationgoal(&sptr->floorz); + i = getanimationgoal(anim_floorz, sn); if (i >= 0) { if (animategoal[sn] == sptr->ceilingz) @@ -748,7 +781,7 @@ void operatesectors(int sn, int ii) sptr->lotag ^= 0x8000; - if (setanimation(sn, &sptr->floorz, j, sptr->extra) >= 0) + if (setanimation(sn, anim_floorz, sn, j, sptr->extra) >= 0) callsound(sn, ii); } return; @@ -758,15 +791,15 @@ void operatesectors(int sn, int ii) if ((sptr->lotag & 0x8000)) { q = (sptr->ceilingz + sptr->floorz) >> 1; - j = setanimation(sn, &sptr->floorz, q, sptr->extra); - j = setanimation(sn, &sptr->ceilingz, q, sptr->extra); + j = setanimation(sn, anim_floorz, sn, q, sptr->extra); + j = setanimation(sn, anim_ceilingz, sn, q, sptr->extra); } else { q = sector[nextsectorneighborz(sn, sptr->floorz, 1, 1)].floorz; - j = setanimation(sn, &sptr->floorz, q, sptr->extra); + j = setanimation(sn, anim_floorz, sn, q, sptr->extra); q = sector[nextsectorneighborz(sn, sptr->ceilingz, -1, -1)].ceilingz; - j = setanimation(sn, &sptr->ceilingz, q, sptr->extra); + j = setanimation(sn, anim_ceilingz, sn, q, sptr->extra); } sptr->lotag ^= 0x8000; diff --git a/source/games/duke/src/zz_global.cpp b/source/games/duke/src/zz_global.cpp index 5fe65e3ab..5f965f990 100644 --- a/source/games/duke/src/zz_global.cpp +++ b/source/games/duke/src/zz_global.cpp @@ -95,7 +95,8 @@ int numplayersprites; int spriteqloc; int16_t animatesect[MAXANIMATES]; -int* animateptr[MAXANIMATES]; +int8_t animatetype[MAXANIMATES]; +int16_t animatetarget[MAXANIMATES]; int animategoal[MAXANIMATES]; int animatevel[MAXANIMATES];