New userdef structure "return"

This works like an extension of the RETURN gamevar and it accepts multiple values. Reading or writing the value of "userdef[].return 0" is the same as reading of writing the RETURN gamevar.

The following userdefs are now aliases:
- m_origin_x = userdef[].return 1
- m_origin_y = userdef[].return 2
- screenarea_x1 = userdef[].return 0
- screenarea_y1 = userdef[].return 1
- screenarea_x1 = userdef[].return 2

Additionally, the API for EVENT_PLAYLEVELMUSICSLOT is hereby redefined to use return 1 and 2 (not 0) _instead of_ ud.m_*_number.

Patch from Fox.

git-svn-id: https://svn.eduke32.com/eduke32@6706 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2018-02-26 20:20:00 +00:00
parent 9878d0c322
commit 4f17a26061
7 changed files with 57 additions and 38 deletions

View file

@ -150,6 +150,8 @@ extern camera_t g_camera;
#define MAXPWLOCKOUT 128 #define MAXPWLOCKOUT 128
#define MAXRTSNAME 128 #define MAXRTSNAME 128
#define MAX_RETURN_VALUES 4
// KEEPINSYNC lunatic/_defs_game.lua // KEEPINSYNC lunatic/_defs_game.lua
typedef struct { typedef struct {
#if !defined LUNATIC #if !defined LUNATIC
@ -165,7 +167,6 @@ typedef struct {
int32_t team, viewbob, weaponsway, althud, weaponscale, textscale; int32_t team, viewbob, weaponsway, althud, weaponscale, textscale;
int32_t statusbarflags, statusbarrange, statusbarcustom; int32_t statusbarflags, statusbarrange, statusbarcustom;
int32_t hudontop; int32_t hudontop;
int32_t screenarea_x1, screenarea_y1, screenarea_x2, screenarea_y2;
int32_t menu_slidebarz, menu_slidebarmargin, menu_slidecursorz; int32_t menu_slidebarz, menu_slidebarmargin, menu_slidecursorz;
int32_t menu_scrollbartilenum, menu_scrollbarz, menu_scrollcursorz; int32_t menu_scrollbartilenum, menu_scrollbarz, menu_scrollcursorz;
@ -179,13 +180,14 @@ typedef struct {
int32_t player_skill,level_number,volume_number,m_marker,marker,mouseflip; int32_t player_skill,level_number,volume_number,m_marker,marker,mouseflip;
int32_t music_episode, music_level; int32_t music_episode, music_level;
vec2_t m_origin;
int32_t playerbest; int32_t playerbest;
int32_t configversion, bgstretch; int32_t configversion, bgstretch;
int32_t default_volume, default_skill; int32_t default_volume, default_skill;
int32_t returnvar[MAX_RETURN_VALUES-1];
#if !defined LUNATIC #if !defined LUNATIC
int16_t cameraang, camerasect, camerahoriz; int16_t cameraang, camerasect, camerahoriz;
#endif #endif

View file

@ -1317,6 +1317,7 @@ const memberlabel_t UserdefsLabels[]=
{ "menu_scrollbartilenum", USERDEFS_MENU_SCROLLBARTILENUM, 0, 0 }, { "menu_scrollbartilenum", USERDEFS_MENU_SCROLLBARTILENUM, 0, 0 },
{ "menu_scrollbarz", USERDEFS_MENU_SCROLLBARZ, 0, 0 }, { "menu_scrollbarz", USERDEFS_MENU_SCROLLBARZ, 0, 0 },
{ "menu_scrollcursorz", USERDEFS_MENU_SCROLLCURSORZ, 0, 0 }, { "menu_scrollcursorz", USERDEFS_MENU_SCROLLCURSORZ, 0, 0 },
{ "return", USERDEFS_RETURN, LABEL_HASPARM2, MAX_RETURN_VALUES },
{ NULL, -1, 0, 0 } // END OF LIST { NULL, -1, 0, 0 } // END OF LIST
}; };

View file

@ -588,6 +588,7 @@ enum UserdefsLabel_t
USERDEFS_MENU_SCROLLBARTILENUM, USERDEFS_MENU_SCROLLBARTILENUM,
USERDEFS_MENU_SCROLLBARZ, USERDEFS_MENU_SCROLLBARZ,
USERDEFS_MENU_SCROLLCURSORZ, USERDEFS_MENU_SCROLLCURSORZ,
USERDEFS_RETURN,
USERDEFS_END USERDEFS_END
}; };

View file

@ -151,8 +151,8 @@ int32_t __fastcall VM_GetUserdef(int32_t labelNum, int32_t const lParm2)
case USERDEFS_WEAPONSCALE: labelNum = ud.weaponscale; break; case USERDEFS_WEAPONSCALE: labelNum = ud.weaponscale; break;
case USERDEFS_TEXTSCALE: labelNum = ud.textscale; break; case USERDEFS_TEXTSCALE: labelNum = ud.textscale; break;
case USERDEFS_RUNKEY_MODE: labelNum = ud.runkey_mode; break; case USERDEFS_RUNKEY_MODE: labelNum = ud.runkey_mode; break;
case USERDEFS_M_ORIGIN_X: labelNum = ud.m_origin.x; break; case USERDEFS_M_ORIGIN_X: labelNum = ud.returnvar[0]; break;
case USERDEFS_M_ORIGIN_Y: labelNum = ud.m_origin.y; break; case USERDEFS_M_ORIGIN_Y: labelNum = ud.returnvar[1]; break;
case USERDEFS_PLAYERBEST: labelNum = ud.playerbest; break; case USERDEFS_PLAYERBEST: labelNum = ud.playerbest; break;
case USERDEFS_MUSICTOGGLE: labelNum = ud.config.MusicToggle; break; case USERDEFS_MUSICTOGGLE: labelNum = ud.config.MusicToggle; break;
case USERDEFS_USEVOXELS: labelNum = usevoxels; break; case USERDEFS_USEVOXELS: labelNum = usevoxels; break;
@ -179,10 +179,10 @@ int32_t __fastcall VM_GetUserdef(int32_t labelNum, int32_t const lParm2)
case USERDEFS_GAMETEXT_TRACKING: labelNum = MF_Bluefont.between.x; break; case USERDEFS_GAMETEXT_TRACKING: labelNum = MF_Bluefont.between.x; break;
case USERDEFS_MENUTEXT_TRACKING: labelNum = MF_Redfont.between.x; break; case USERDEFS_MENUTEXT_TRACKING: labelNum = MF_Redfont.between.x; break;
case USERDEFS_MAXSPRITESONSCREEN: labelNum = maxspritesonscreen; break; case USERDEFS_MAXSPRITESONSCREEN: labelNum = maxspritesonscreen; break;
case USERDEFS_SCREENAREA_X1: labelNum = ud.screenarea_x1; break; case USERDEFS_SCREENAREA_X1: labelNum = aGameVars[g_returnVarID].global; break;
case USERDEFS_SCREENAREA_Y1: labelNum = ud.screenarea_y1; break; case USERDEFS_SCREENAREA_Y1: labelNum = ud.returnvar[0]; break;
case USERDEFS_SCREENAREA_X2: labelNum = ud.screenarea_x2; break; case USERDEFS_SCREENAREA_X2: labelNum = ud.returnvar[1]; break;
case USERDEFS_SCREENAREA_Y2: labelNum = ud.screenarea_y2; break; case USERDEFS_SCREENAREA_Y2: labelNum = ud.returnvar[2]; break;
case USERDEFS_SCREENFADE: labelNum = ud.screenfade; break; case USERDEFS_SCREENFADE: labelNum = ud.screenfade; break;
case USERDEFS_MENUBACKGROUND: labelNum = ud.menubackground; break; case USERDEFS_MENUBACKGROUND: labelNum = ud.menubackground; break;
case USERDEFS_STATUSBARFLAGS: labelNum = ud.statusbarflags; break; case USERDEFS_STATUSBARFLAGS: labelNum = ud.statusbarflags; break;
@ -224,6 +224,12 @@ int32_t __fastcall VM_GetUserdef(int32_t labelNum, int32_t const lParm2)
case USERDEFS_MENU_SCROLLBARTILENUM: labelNum = ud.menu_scrollbartilenum; break; case USERDEFS_MENU_SCROLLBARTILENUM: labelNum = ud.menu_scrollbartilenum; break;
case USERDEFS_MENU_SCROLLBARZ: labelNum = ud.menu_scrollbarz; break; case USERDEFS_MENU_SCROLLBARZ: labelNum = ud.menu_scrollbarz; break;
case USERDEFS_MENU_SCROLLCURSORZ: labelNum = ud.menu_scrollcursorz; break; case USERDEFS_MENU_SCROLLCURSORZ: labelNum = ud.menu_scrollcursorz; break;
case USERDEFS_RETURN:
if (lParm2 == 0)
labelNum = aGameVars[g_returnVarID].global;
else
labelNum = ud.returnvar[lParm2-1];
break;
default: labelNum = -1; break; default: labelNum = -1; break;
} }
@ -341,8 +347,8 @@ void __fastcall VM_SetUserdef(int32_t const labelNum, int32_t const lParm2, int3
case USERDEFS_WEAPONSCALE: ud.weaponscale = iSet; break; case USERDEFS_WEAPONSCALE: ud.weaponscale = iSet; break;
case USERDEFS_TEXTSCALE: ud.textscale = iSet; break; case USERDEFS_TEXTSCALE: ud.textscale = iSet; break;
case USERDEFS_RUNKEY_MODE: ud.runkey_mode = iSet; break; case USERDEFS_RUNKEY_MODE: ud.runkey_mode = iSet; break;
case USERDEFS_M_ORIGIN_X: ud.m_origin.x = iSet; break; case USERDEFS_M_ORIGIN_X: ud.returnvar[0] = iSet; break;
case USERDEFS_M_ORIGIN_Y: ud.m_origin.y = iSet; break; case USERDEFS_M_ORIGIN_Y: ud.returnvar[1] = iSet; break;
case USERDEFS_GLOBALFLAGS: globalflags = iSet; break; case USERDEFS_GLOBALFLAGS: globalflags = iSet; break;
case USERDEFS_GLOBALGAMEFLAGS: duke3d_globalflags = iSet; break; case USERDEFS_GLOBALGAMEFLAGS: duke3d_globalflags = iSet; break;
case USERDEFS_VM_PLAYER: vm.playerNum = iSet; vm.pPlayer = g_player[iSet].ps; break; case USERDEFS_VM_PLAYER: vm.playerNum = iSet; vm.pPlayer = g_player[iSet].ps; break;
@ -351,10 +357,10 @@ void __fastcall VM_SetUserdef(int32_t const labelNum, int32_t const lParm2, int3
case USERDEFS_GAMETEXT_TRACKING: MF_Bluefont.between.x = iSet; break; case USERDEFS_GAMETEXT_TRACKING: MF_Bluefont.between.x = iSet; break;
case USERDEFS_MENUTEXT_TRACKING: MF_Redfont.between.x = iSet; break; case USERDEFS_MENUTEXT_TRACKING: MF_Redfont.between.x = iSet; break;
case USERDEFS_MAXSPRITESONSCREEN: maxspritesonscreen = clamp(iSet, MAXSPRITESONSCREEN>>2, MAXSPRITESONSCREEN); break; case USERDEFS_MAXSPRITESONSCREEN: maxspritesonscreen = clamp(iSet, MAXSPRITESONSCREEN>>2, MAXSPRITESONSCREEN); break;
case USERDEFS_SCREENAREA_X1: ud.screenarea_x1 = iSet; break; case USERDEFS_SCREENAREA_X1: aGameVars[g_returnVarID].global = iSet; break;
case USERDEFS_SCREENAREA_Y1: ud.screenarea_y1 = iSet; break; case USERDEFS_SCREENAREA_Y1: ud.returnvar[0] = iSet; break;
case USERDEFS_SCREENAREA_X2: ud.screenarea_x2 = iSet; break; case USERDEFS_SCREENAREA_X2: ud.returnvar[1] = iSet; break;
case USERDEFS_SCREENAREA_Y2: ud.screenarea_y2 = iSet; break; case USERDEFS_SCREENAREA_Y2: ud.returnvar[2] = iSet; break;
case USERDEFS_SCREENFADE: ud.screenfade = iSet; break; case USERDEFS_SCREENFADE: ud.screenfade = iSet; break;
case USERDEFS_MENUBACKGROUND: ud.menubackground = iSet; break; case USERDEFS_MENUBACKGROUND: ud.menubackground = iSet; break;
case USERDEFS_STATUSBARFLAGS: ud.statusbarflags = iSet; break; case USERDEFS_STATUSBARFLAGS: ud.statusbarflags = iSet; break;
@ -406,6 +412,12 @@ void __fastcall VM_SetUserdef(int32_t const labelNum, int32_t const lParm2, int3
case USERDEFS_MENU_SCROLLBARTILENUM: ud.menu_scrollbartilenum = iSet; break; case USERDEFS_MENU_SCROLLBARTILENUM: ud.menu_scrollbartilenum = iSet; break;
case USERDEFS_MENU_SCROLLBARZ: ud.menu_scrollbarz = iSet; break; case USERDEFS_MENU_SCROLLBARZ: ud.menu_scrollbarz = iSet; break;
case USERDEFS_MENU_SCROLLCURSORZ: ud.menu_scrollcursorz = iSet; break; case USERDEFS_MENU_SCROLLCURSORZ: ud.menu_scrollcursorz = iSet; break;
case USERDEFS_RETURN:
if (lParm2 == 0)
aGameVars[g_returnVarID].global = iSet;
else
ud.returnvar[lParm2-1] = iSet;
break;
default: break; default: break;
} }
} }

View file

@ -6660,9 +6660,11 @@ void M_DisplayMenus(void)
if (m_parentMenu) if (m_parentMenu)
{ {
ud.m_origin = origin; ud.returnvar[0] = origin.x;
ud.returnvar[1] = origin.y;
VM_OnEventWithReturn(EVENT_DISPLAYINACTIVEMENU, g_player[screenpeek].ps->i, screenpeek, m_parentMenu->menuID); VM_OnEventWithReturn(EVENT_DISPLAYINACTIVEMENU, g_player[screenpeek].ps->i, screenpeek, m_parentMenu->menuID);
origin = ud.m_origin; origin.x = ud.returnvar[0];
origin.y = ud.returnvar[1];
} }
// Determine animation values. // Determine animation values.
@ -6673,14 +6675,18 @@ void M_DisplayMenus(void)
origin.x = mulscale15(screenwidth, m_animation.in(&m_animation)); origin.x = mulscale15(screenwidth, m_animation.in(&m_animation));
previousOrigin.x = mulscale15(screenwidth, m_animation.out(&m_animation)); previousOrigin.x = mulscale15(screenwidth, m_animation.out(&m_animation));
ud.m_origin = previousOrigin; ud.returnvar[0] = previousOrigin.x;
ud.returnvar[1] = previousOrigin.y;
VM_OnEventWithReturn(EVENT_DISPLAYINACTIVEMENU, g_player[screenpeek].ps->i, screenpeek, m_animation.previous->menuID); VM_OnEventWithReturn(EVENT_DISPLAYINACTIVEMENU, g_player[screenpeek].ps->i, screenpeek, m_animation.previous->menuID);
previousOrigin = ud.m_origin; previousOrigin.x = ud.returnvar[0];
previousOrigin.y = ud.returnvar[1];
} }
ud.m_origin = origin; ud.returnvar[0] = origin.x;
ud.returnvar[1] = origin.y;
VM_OnEventWithReturn(EVENT_DISPLAYMENU, g_player[screenpeek].ps->i, screenpeek, g_currentMenu); VM_OnEventWithReturn(EVENT_DISPLAYMENU, g_player[screenpeek].ps->i, screenpeek, g_currentMenu);
origin = ud.m_origin; origin.x = ud.returnvar[0];
origin.y = ud.returnvar[1];
if (m_parentMenu && backgroundOK) if (m_parentMenu && backgroundOK)
{ {
@ -6707,17 +6713,20 @@ void M_DisplayMenus(void)
if (m_parentMenu) if (m_parentMenu)
{ {
ud.m_origin = origin; ud.returnvar[0] = origin.x;
ud.returnvar[1] = origin.y;
VM_OnEventWithReturn(EVENT_DISPLAYINACTIVEMENUREST, g_player[screenpeek].ps->i, screenpeek, m_parentMenu->menuID); VM_OnEventWithReturn(EVENT_DISPLAYINACTIVEMENUREST, g_player[screenpeek].ps->i, screenpeek, m_parentMenu->menuID);
} }
if (totalclock < m_animation.start + m_animation.length) if (totalclock < m_animation.start + m_animation.length)
{ {
ud.m_origin = previousOrigin; ud.returnvar[0] = previousOrigin.x;
ud.returnvar[1] = previousOrigin.y;
VM_OnEventWithReturn(EVENT_DISPLAYINACTIVEMENUREST, g_player[screenpeek].ps->i, screenpeek, m_animation.previous->menuID); VM_OnEventWithReturn(EVENT_DISPLAYINACTIVEMENUREST, g_player[screenpeek].ps->i, screenpeek, m_animation.previous->menuID);
} }
ud.m_origin = origin; ud.returnvar[0] = origin.x;
ud.returnvar[1] = origin.y;
VM_OnEventWithReturn(EVENT_DISPLAYMENUREST, g_player[screenpeek].ps->i, screenpeek, g_currentMenu); VM_OnEventWithReturn(EVENT_DISPLAYMENUREST, g_player[screenpeek].ps->i, screenpeek, g_currentMenu);
#if !defined EDUKE32_TOUCH_DEVICES #if !defined EDUKE32_TOUCH_DEVICES

View file

@ -601,15 +601,13 @@ void G_UpdateScreenArea(void)
if (VM_HaveEvent(EVENT_UPDATESCREENAREA)) if (VM_HaveEvent(EVENT_UPDATESCREENAREA))
{ {
ud.screenarea_x1 = x1; ud.returnvar[0] = y1;
ud.screenarea_y1 = y1; ud.returnvar[1] = x2;
ud.screenarea_x2 = x2; ud.returnvar[2] = y2;
ud.screenarea_y2 = y2; x1 = VM_OnEventWithReturn(EVENT_UPDATESCREENAREA, g_player[screenpeek].ps->i, screenpeek, x1);
VM_OnEvent(EVENT_UPDATESCREENAREA, g_player[screenpeek].ps->i, screenpeek); y1 = ud.returnvar[0];
x1 = ud.screenarea_x1; x2 = ud.returnvar[1];
y1 = ud.screenarea_y1; y2 = ud.returnvar[2];
x2 = ud.screenarea_x2;
y2 = ud.screenarea_y2;
} }
if (g_halveScreenArea) if (g_halveScreenArea)

View file

@ -280,13 +280,9 @@ static void S_SetMusicIndex(unsigned int m)
int S_TryPlayLevelMusic(unsigned int m) int S_TryPlayLevelMusic(unsigned int m)
{ {
auto m_volume_number = ud.m_volume_number; ud.returnvar[0] = m / MAXLEVELS;
auto m_level_number = ud.m_level_number; ud.returnvar[1] = m % MAXLEVELS;
ud.m_volume_number = m / MAXLEVELS;
ud.m_level_number = m % MAXLEVELS;
int retval = VM_OnEvent(EVENT_PLAYLEVELMUSICSLOT, g_player[myconnectindex].ps->i, myconnectindex); int retval = VM_OnEvent(EVENT_PLAYLEVELMUSICSLOT, g_player[myconnectindex].ps->i, myconnectindex);
ud.m_volume_number = m_volume_number;
ud.m_level_number = m_level_number;
if (retval < 0) if (retval < 0)
return 0; return 0;