diff --git a/source/duke3d/src/game.h b/source/duke3d/src/game.h index e44299067..6ba96156c 100644 --- a/source/duke3d/src/game.h +++ b/source/duke3d/src/game.h @@ -150,6 +150,8 @@ extern camera_t g_camera; #define MAXPWLOCKOUT 128 #define MAXRTSNAME 128 +#define MAX_RETURN_VALUES 4 + // KEEPINSYNC lunatic/_defs_game.lua typedef struct { #if !defined LUNATIC @@ -165,7 +167,6 @@ typedef struct { int32_t team, viewbob, weaponsway, althud, weaponscale, textscale; int32_t statusbarflags, statusbarrange, statusbarcustom; int32_t hudontop; - int32_t screenarea_x1, screenarea_y1, screenarea_x2, screenarea_y2; int32_t menu_slidebarz, menu_slidebarmargin, menu_slidecursorz; 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 music_episode, music_level; - vec2_t m_origin; int32_t playerbest; int32_t configversion, bgstretch; int32_t default_volume, default_skill; + int32_t returnvar[MAX_RETURN_VALUES-1]; + #if !defined LUNATIC int16_t cameraang, camerasect, camerahoriz; #endif diff --git a/source/duke3d/src/gamedef.cpp b/source/duke3d/src/gamedef.cpp index 9fc178ed0..2d0b86045 100644 --- a/source/duke3d/src/gamedef.cpp +++ b/source/duke3d/src/gamedef.cpp @@ -1317,6 +1317,7 @@ const memberlabel_t UserdefsLabels[]= { "menu_scrollbartilenum", USERDEFS_MENU_SCROLLBARTILENUM, 0, 0 }, { "menu_scrollbarz", USERDEFS_MENU_SCROLLBARZ, 0, 0 }, { "menu_scrollcursorz", USERDEFS_MENU_SCROLLCURSORZ, 0, 0 }, + { "return", USERDEFS_RETURN, LABEL_HASPARM2, MAX_RETURN_VALUES }, { NULL, -1, 0, 0 } // END OF LIST }; diff --git a/source/duke3d/src/gamedef.h b/source/duke3d/src/gamedef.h index 33d52318c..0aceade91 100644 --- a/source/duke3d/src/gamedef.h +++ b/source/duke3d/src/gamedef.h @@ -588,6 +588,7 @@ enum UserdefsLabel_t USERDEFS_MENU_SCROLLBARTILENUM, USERDEFS_MENU_SCROLLBARZ, USERDEFS_MENU_SCROLLCURSORZ, + USERDEFS_RETURN, USERDEFS_END }; diff --git a/source/duke3d/src/gamestructures.cpp b/source/duke3d/src/gamestructures.cpp index 18aa0ad81..048505a70 100644 --- a/source/duke3d/src/gamestructures.cpp +++ b/source/duke3d/src/gamestructures.cpp @@ -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_TEXTSCALE: labelNum = ud.textscale; 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_Y: labelNum = ud.m_origin.y; break; + case USERDEFS_M_ORIGIN_X: labelNum = ud.returnvar[0]; break; + case USERDEFS_M_ORIGIN_Y: labelNum = ud.returnvar[1]; break; case USERDEFS_PLAYERBEST: labelNum = ud.playerbest; break; case USERDEFS_MUSICTOGGLE: labelNum = ud.config.MusicToggle; 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_MENUTEXT_TRACKING: labelNum = MF_Redfont.between.x; break; case USERDEFS_MAXSPRITESONSCREEN: labelNum = maxspritesonscreen; break; - case USERDEFS_SCREENAREA_X1: labelNum = ud.screenarea_x1; break; - case USERDEFS_SCREENAREA_Y1: labelNum = ud.screenarea_y1; break; - case USERDEFS_SCREENAREA_X2: labelNum = ud.screenarea_x2; break; - case USERDEFS_SCREENAREA_Y2: labelNum = ud.screenarea_y2; break; + case USERDEFS_SCREENAREA_X1: labelNum = aGameVars[g_returnVarID].global; break; + case USERDEFS_SCREENAREA_Y1: labelNum = ud.returnvar[0]; break; + case USERDEFS_SCREENAREA_X2: labelNum = ud.returnvar[1]; break; + case USERDEFS_SCREENAREA_Y2: labelNum = ud.returnvar[2]; break; case USERDEFS_SCREENFADE: labelNum = ud.screenfade; break; case USERDEFS_MENUBACKGROUND: labelNum = ud.menubackground; 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_SCROLLBARZ: labelNum = ud.menu_scrollbarz; 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; } @@ -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_TEXTSCALE: ud.textscale = 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_Y: ud.m_origin.y = iSet; break; + case USERDEFS_M_ORIGIN_X: ud.returnvar[0] = iSet; break; + case USERDEFS_M_ORIGIN_Y: ud.returnvar[1] = iSet; break; case USERDEFS_GLOBALFLAGS: globalflags = iSet; break; case USERDEFS_GLOBALGAMEFLAGS: duke3d_globalflags = iSet; 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_MENUTEXT_TRACKING: MF_Redfont.between.x = iSet; break; case USERDEFS_MAXSPRITESONSCREEN: maxspritesonscreen = clamp(iSet, MAXSPRITESONSCREEN>>2, MAXSPRITESONSCREEN); break; - case USERDEFS_SCREENAREA_X1: ud.screenarea_x1 = iSet; break; - case USERDEFS_SCREENAREA_Y1: ud.screenarea_y1 = iSet; break; - case USERDEFS_SCREENAREA_X2: ud.screenarea_x2 = iSet; break; - case USERDEFS_SCREENAREA_Y2: ud.screenarea_y2 = iSet; break; + case USERDEFS_SCREENAREA_X1: aGameVars[g_returnVarID].global = iSet; break; + case USERDEFS_SCREENAREA_Y1: ud.returnvar[0] = iSet; break; + case USERDEFS_SCREENAREA_X2: ud.returnvar[1] = iSet; break; + case USERDEFS_SCREENAREA_Y2: ud.returnvar[2] = iSet; break; case USERDEFS_SCREENFADE: ud.screenfade = iSet; break; case USERDEFS_MENUBACKGROUND: ud.menubackground = 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_SCROLLBARZ: ud.menu_scrollbarz = 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; } } diff --git a/source/duke3d/src/menus.cpp b/source/duke3d/src/menus.cpp index 1dad5a19f..8036db467 100644 --- a/source/duke3d/src/menus.cpp +++ b/source/duke3d/src/menus.cpp @@ -6660,9 +6660,11 @@ void M_DisplayMenus(void) 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); - origin = ud.m_origin; + origin.x = ud.returnvar[0]; + origin.y = ud.returnvar[1]; } // Determine animation values. @@ -6673,14 +6675,18 @@ void M_DisplayMenus(void) origin.x = mulscale15(screenwidth, m_animation.in(&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); - 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); - origin = ud.m_origin; + origin.x = ud.returnvar[0]; + origin.y = ud.returnvar[1]; if (m_parentMenu && backgroundOK) { @@ -6707,17 +6713,20 @@ void M_DisplayMenus(void) 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); } 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); } - 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); #if !defined EDUKE32_TOUCH_DEVICES diff --git a/source/duke3d/src/premap.cpp b/source/duke3d/src/premap.cpp index 3afe33215..d56b80d89 100644 --- a/source/duke3d/src/premap.cpp +++ b/source/duke3d/src/premap.cpp @@ -601,15 +601,13 @@ void G_UpdateScreenArea(void) if (VM_HaveEvent(EVENT_UPDATESCREENAREA)) { - ud.screenarea_x1 = x1; - ud.screenarea_y1 = y1; - ud.screenarea_x2 = x2; - ud.screenarea_y2 = y2; - VM_OnEvent(EVENT_UPDATESCREENAREA, g_player[screenpeek].ps->i, screenpeek); - x1 = ud.screenarea_x1; - y1 = ud.screenarea_y1; - x2 = ud.screenarea_x2; - y2 = ud.screenarea_y2; + ud.returnvar[0] = y1; + ud.returnvar[1] = x2; + ud.returnvar[2] = y2; + x1 = VM_OnEventWithReturn(EVENT_UPDATESCREENAREA, g_player[screenpeek].ps->i, screenpeek, x1); + y1 = ud.returnvar[0]; + x2 = ud.returnvar[1]; + y2 = ud.returnvar[2]; } if (g_halveScreenArea) diff --git a/source/duke3d/src/sounds.cpp b/source/duke3d/src/sounds.cpp index de3939638..5215601be 100644 --- a/source/duke3d/src/sounds.cpp +++ b/source/duke3d/src/sounds.cpp @@ -280,13 +280,9 @@ static void S_SetMusicIndex(unsigned int m) int S_TryPlayLevelMusic(unsigned int m) { - auto m_volume_number = ud.m_volume_number; - auto m_level_number = ud.m_level_number; - ud.m_volume_number = m / MAXLEVELS; - ud.m_level_number = m % MAXLEVELS; + ud.returnvar[0] = m / MAXLEVELS; + ud.returnvar[1] = m % MAXLEVELS; 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) return 0;