Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a "prev map" key binding #2046

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/g_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,53 @@ int G_GotoNextLevel(int *pEpi, int *pMap)
return false;
}

int G_GotoPrevLevel(void)
{
const int cur_epsd = gameepisode;
const int cur_map = gamemap;
int epsd_count, map_count;
int ret = false;

for (epsd_count = 0; epsd_count < 10; epsd_count++, gameepisode = (gameepisode + 9) % 10)
{
for (map_count= 0, gamemap--; map_count < 100; map_count++, gamemap = (gamemap + 99) % 100)
{
int next_epsd, next_map;
G_GotoNextLevel(&next_epsd, &next_map);

if (next_epsd == cur_epsd && next_map == cur_map &&
(gameepisode != cur_epsd || gamemap != cur_map))
{
char *name = MapName(gameepisode, gamemap);

if (W_CheckNumForName(name) != -1)
{
G_DeferedInitNew(gameskill, gameepisode, gamemap);
ret = true;
break;
}
}
}

// only check one episode in Doom 2
if (gamemode == commercial)
{
break;
}
}

gameepisode = cur_epsd;
gamemap = cur_map;

if (ret == false)
{
char *name = MapName(gameepisode, gamemap);
displaymsg("Previous level not found for %s", name);
}

return ret;
}

static boolean G_StrictModeSkipEvent(event_t *ev)
{
static boolean enable_mouse = false;
Expand Down
1 change: 1 addition & 0 deletions src/g_game.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ demo_version_t G_GetNamedComplevel(const char *arg);
const char *G_GetCurrentComplevelName(void);

int G_GotoNextLevel(int *pEpi, int *pMap);
int G_GotoPrevLevel(void);

void G_BindGameInputVariables(void);
void G_BindGameVariables(void);
Expand Down
1 change: 1 addition & 0 deletions src/m_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ void M_BindInputVariables(void)

BIND_INPUT(input_menu_reloadlevel, "Restart current level/demo");
BIND_INPUT(input_menu_nextlevel, "Go to next level");
BIND_INPUT(input_menu_prevlevel, "Go to previous level");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's config only? We don't have room for it in the "Key Bindings" menu. Maybe we should move player 1-4 to config:
image

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's a good solution.


BIND_INPUT(input_hud_timestats, "Toggle display of level stats and time");

Expand Down
1 change: 1 addition & 0 deletions src/m_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ enum
input_menu_clear,
input_menu_reloadlevel,
input_menu_nextlevel,
input_menu_prevlevel,

input_hud_timestats,

Expand Down
12 changes: 12 additions & 0 deletions src/mn_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
CHOICE_VALUE = 0,
} mchoice_t;

typedef struct

Check warning on line 150 in src/mn_menu.c

View workflow job for this annotation

GitHub Actions / Clang-Tidy

src/mn_menu.c:150:9 [clang-analyzer-optin.performance.Padding]

Excessive padding in 'menuitem_t' (15 padding bytes, where 7 is optimal). Optimal fields order: routine, alttext, flags, status, rect, alphaKey, name, consider reordering the fields or adding explicit padding members
{
short status; // 0 = no cursor here, 1 = ok, 2 = arrows ok
char name[10];
Expand Down Expand Up @@ -2608,6 +2608,18 @@
}
}

if (M_InputActivated(input_menu_prevlevel))
{
if (demoplayback && singledemo && !PLAYBACK_SKIP)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this part.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Next Level" works during demoplayback. "Prev Level" would not be so practical - we would have to restart the demo from the beginning. I think we need demo compatible save/rewind to implement the "Prev Level" feature well.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need demo compatible save/rewind to implement the "Prev Level" feature well.

For demos, yes. But for regular play?

What if you start the game with -warp 1 2 and hit the "prev level" button? I would expect it to go back to E1M1, although this map has not been visited in the current run.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For demos, yes. But for regular play?

Yes, I was talking about demos. Sure, we can implement "prev map" without demo playback support.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Demo support for "prev level" would be very useful.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Demo support for "prev level" would be very useful.

Then it will take a while until we have demo-compatible saves. DSDA-Doom has an implementation of it, but I want to try to extend zone memory with "relative pointers" idea: https://nullprogram.com/blog/2023/09/30/

instead of pointers I use signed integers whose value indicates an offset relative to itself

This would allow us to save/restore the entire playsim with a single memcpy. Not sure if this will work though.

{
return false;
}
else if (G_GotoPrevLevel())
{
return true;
}
}

if (M_InputActivated(input_demo_fforward))
{
if (demoplayback && !PLAYBACK_SKIP && !fastdemo && !D_CheckNetConnect())
Expand Down