From 9a889301e05939d69c64b4b5b6839bbe0b5cd547 Mon Sep 17 00:00:00 2001 From: Fabian Greffrath Date: Tue, 28 Jan 2025 13:55:01 +0100 Subject: [PATCH] save button states in savegames (#2165) * save button states in savegames Mostly taken from Doom Retro. * simplify loop * simplify restoring button state --- src/p_saveg.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++- src/p_spec.h | 2 ++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index 3254037b..bc9b90c2 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -2005,6 +2005,41 @@ static void saveg_write_rng_t(rng_t *str) saveg_write32(str->prndindex); } +// +// button_t +// + +static void saveg_read_button_t(button_t *str) +{ + // line_t *line + int line = saveg_read32(); + str->line = &lines[line]; + + // bwhere_e where + str->where = (bwhere_e)saveg_read32(); + + // int btexture + str->btexture = saveg_read32(); + + // int btimer + str->btimer = saveg_read32(); +} + +static void saveg_write_button_t(button_t *str) +{ + // line_t *line + saveg_write32(str->line - lines); + + // bwhere_e where + saveg_write32((int)str->where); + + // int btexture + saveg_write32(str->btexture); + + // int btimer + saveg_write32(str->btimer); +} + // // P_ArchivePlayers // @@ -2463,7 +2498,8 @@ enum { tc_pusher, // phares 3/22/98: new push/pull effect thinker tc_flicker, // killough 10/4/98 tc_endspecials, - tc_friction // store friction for complevel Boom + tc_friction, // store friction for complevel Boom + tc_button, } specials_e; // @@ -2653,6 +2689,18 @@ void P_ArchiveSpecials (void) } } + CheckSaveGame(MAXBUTTONS * sizeof(button_t)); + + for (int i = 0; i < MAXBUTTONS; i++) + { + if (buttonlist[i].btimer != 0) + { + saveg_write8(tc_button); + saveg_write_pad(); + saveg_write_button_t(&buttonlist[i]); + } + } + // add a terminating marker saveg_write8(tc_endspecials); } @@ -2811,6 +2859,13 @@ void P_UnArchiveSpecials (void) break; } + case tc_button: + saveg_read_pad(); + button_t button; + saveg_read_button_t(&button); + P_StartButton(button.line, button.where, button.btexture, button.btimer); + break; + default: I_Error ("P_UnarchiveSpecials:Unknown tclass %i " "in savegame",tclass); diff --git a/src/p_spec.h b/src/p_spec.h index fc84996d..37159328 100644 --- a/src/p_spec.h +++ b/src/p_spec.h @@ -536,6 +536,8 @@ typedef struct struct mobj_s *soundorg; } button_t; +void P_StartButton(struct line_s *line, bwhere_e w, int texture, int time); + // p_lights typedef struct