Skip to content

Commit

Permalink
save button states in savegames (#2165)
Browse files Browse the repository at this point in the history
* save button states in savegames

Mostly taken from Doom Retro.

* simplify loop

* simplify restoring button state
  • Loading branch information
fabiangreffrath authored Jan 28, 2025
1 parent 4089139 commit 9a88930
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
57 changes: 56 additions & 1 deletion src/p_saveg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down Expand Up @@ -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;

//
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/p_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9a88930

Please sign in to comment.