From d5772ff8955efd5af76c45292c5a967a8658d1a6 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 28 Mar 2017 22:34:12 +0200 Subject: [PATCH 01/11] - fixed: SafeCommand did not work anymore because it failed the abuse prevention check for DoCommand. --- wadsrc/static/zscript/menu/optionmenuitems.txt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/wadsrc/static/zscript/menu/optionmenuitems.txt b/wadsrc/static/zscript/menu/optionmenuitems.txt index 2bbb4a82b..01771a372 100644 --- a/wadsrc/static/zscript/menu/optionmenuitems.txt +++ b/wadsrc/static/zscript/menu/optionmenuitems.txt @@ -132,11 +132,14 @@ class OptionMenuItemCommand : OptionMenuItemSubmenu override bool Activate() { // This needs to perform a few checks to prevent abuse by malicious modders. - let m = OptionMenu(Menu.GetCurrentMenu()); - // don't execute if no menu is active - if (m == null) return false; - // don't execute if this item cannot be found in the current menu. - if (m.GetItem(mAction) != self) return false; + if (GetClass() != "OptionMenuItemSafeCommand") + { + let m = OptionMenu(Menu.GetCurrentMenu()); + // don't execute if no menu is active + if (m == null) return false; + // don't execute if this item cannot be found in the current menu. + if (m.GetItem(mAction) != self) return false; + } Menu.MenuSound("menu/choose"); DoCommand(mAction); return true; From fa893c082b679849c74838ec112f317651459c92 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 28 Mar 2017 22:51:37 +0200 Subject: [PATCH 02/11] - changed the default for hud_scale to 0 (i.e. use uiscale) - allow calling Menu.SetMenu from play code so that in-game menus can be opened. --- src/g_statusbar/shared_sbar.cpp | 2 +- src/gameconfigfile.cpp | 2 +- src/version.h | 2 +- wadsrc/static/zscript/menu/menu.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index 240c30fac..229cfb5e0 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -84,7 +84,7 @@ EXTERN_CVAR (Bool, am_showtotaltime) EXTERN_CVAR (Bool, noisedebug) EXTERN_CVAR (Int, con_scaletext) EXTERN_CVAR(Bool, vid_fps) -CVAR(Int, hud_scale, -1, CVAR_ARCHIVE); +CVAR(Int, hud_scale, 0, CVAR_ARCHIVE); int active_con_scaletext(); diff --git a/src/gameconfigfile.cpp b/src/gameconfigfile.cpp index 03f865a99..cd221958d 100644 --- a/src/gameconfigfile.cpp +++ b/src/gameconfigfile.cpp @@ -354,7 +354,7 @@ void FGameConfigFile::DoGlobalSetup () SetValueForKey ("5", "use ArtiInvulnerability2"); } } - if (last < 212) + if (last < 213) { FBaseCVar *var = FindCVar("hud_scale", NULL); if (var != NULL) diff --git a/src/version.h b/src/version.h index 5e357402f..a3bb6d199 100644 --- a/src/version.h +++ b/src/version.h @@ -66,7 +66,7 @@ const char *GetVersionString(); // Version stored in the ini's [LastRun] section. // Bump it if you made some configuration change that you want to // be able to migrate in FGameConfigFile::DoGlobalSetup(). -#define LASTRUNVERSION "212" +#define LASTRUNVERSION "213" // Protocol version used in demos. // Bump it if you change existing DEM_ commands or add new ones. diff --git a/wadsrc/static/zscript/menu/menu.txt b/wadsrc/static/zscript/menu/menu.txt index d29211b77..09f5d9cde 100644 --- a/wadsrc/static/zscript/menu/menu.txt +++ b/wadsrc/static/zscript/menu/menu.txt @@ -94,7 +94,7 @@ class Menu : Object native ui version("2.4") native static int MenuTime(); native static void SetVideoMode(); native static Menu GetCurrentMenu(); - native static void SetMenu(Name mnu, int param = 0); + native static clearscope void SetMenu(Name mnu, int param = 0); // This is not 100% safe but needs to be available - but always make sure to check that only the desired player opens it! native static void StartMessage(String msg, int mode = 0, Name command = 'none'); native static void SetMouseCapture(bool on); native void Close(); From 5e3e4a3bd1223d584a0842331755caab860037bd Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 28 Mar 2017 23:36:26 +0200 Subject: [PATCH 03/11] - fixed: The wall spliter for 3D lights did not initialize the resulting colormap's fog density value. --- src/gl/scene/gl_walls_draw.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gl/scene/gl_walls_draw.cpp b/src/gl/scene/gl_walls_draw.cpp index 785bdc708..d69ceeb4d 100644 --- a/src/gl/scene/gl_walls_draw.cpp +++ b/src/gl/scene/gl_walls_draw.cpp @@ -371,6 +371,7 @@ void GLWall::RenderTextured(int rflags) int thisll = (*lightlist)[i].caster != NULL ? gl_ClampLight(*(*lightlist)[i].p_lightlevel) : lightlevel; FColormap thiscm; thiscm.FadeColor = Colormap.FadeColor; + thiscm.FogDensity = Colormap.FogDensity; thiscm.CopyFrom3DLight(&(*lightlist)[i]); mDrawer->SetColor(thisll, rel, thiscm, absalpha); if (type != RENDERWALL_M2SNF) mDrawer->SetFog(thisll, rel, &thiscm, RenderStyle == STYLE_Add); From 2d1641f0cd0837c2d07cd95783ae69354d266795 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Mar 2017 00:00:25 +0200 Subject: [PATCH 04/11] - fixed: Reference types passed as a reference parameter were not properly checked for. --- src/scripting/backend/codegen.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index 86e0a4a55..2a178a249 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -8816,12 +8816,15 @@ FxExpression *FxVMFunctionCall::Resolve(FCompileContext& ctx) ArgList[i] = ArgList[i]->Resolve(ctx); // nust be resolved before the address is requested. if (ArgList[i] != nullptr && ArgList[i]->ValueType != TypeNullPtr) { - ArgList[i]->RequestAddress(ctx, &writable); - if (flag & VARF_Ref) ArgList[i]->ValueType = NewPointer(ArgList[i]->ValueType); + if (type != ArgList[i]->ValueType) + { + ArgList[i]->RequestAddress(ctx, &writable); + if (flag & VARF_Ref)ArgList[i]->ValueType = NewPointer(ArgList[i]->ValueType); + } // For a reference argument the types must match 100%. if (type != ArgList[i]->ValueType) { - ScriptPosition.Message(MSG_ERROR, "Type mismatch in reference argument %s", Function->SymbolName.GetChars()); + ScriptPosition.Message(MSG_ERROR, "Type mismatch in reference argument %s: %s != %s", Function->SymbolName.GetChars(), type->DescriptiveName(), ArgList[i]->ValueType->DescriptiveName()); x = nullptr; } else From 19e7d60275505b9af72cf0aa70424c919c068d6c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Mar 2017 00:35:35 +0200 Subject: [PATCH 05/11] - removed DSBarInfo::Scaled because it tended to disagree with StatusBar->Scaled. --- src/g_statusbar/sbarinfo.cpp | 28 +++++-------------- src/scripting/backend/codegen.cpp | 9 ++++-- .../zscript/statusbar/sbarinfowrapper.txt | 7 ----- 3 files changed, 14 insertions(+), 30 deletions(-) diff --git a/src/g_statusbar/sbarinfo.cpp b/src/g_statusbar/sbarinfo.cpp index c64dbef65..9f069b831 100644 --- a/src/g_statusbar/sbarinfo.cpp +++ b/src/g_statusbar/sbarinfo.cpp @@ -1003,11 +1003,6 @@ public: Images.Uninit(); } - void _SetScaled(bool scaled) - { - Scaled = scaled; - } - void _AttachToPlayer(player_t *player) { CPlayer = player; @@ -1039,7 +1034,7 @@ public: { if(script->huds[hud]->FullScreenOffsets()) wrapper->ForceHUDScale(true); - else if(!Scaled) + else if(!wrapper->Scaled) { scalingWasForced = true; wrapper->SetScaled(true, true); @@ -1208,7 +1203,7 @@ public: int barW = wrapper->HorizontalResolution, barH = wrapper->VerticalResolution; dx += wrapper->ST_X; - dy += wrapper->ST_Y - (Scaled ? barH : 200) + script->height; + dy += wrapper->ST_Y - (wrapper->Scaled ? barH : 200) + script->height; w = forceWidth < 0 ? texture->GetScaledWidthDouble() : forceWidth; h = forceHeight < 0 ? texture->GetScaledHeightDouble() : forceHeight; double dcx = clip[0] == 0 ? 0 : dx + clip[0] - texture->GetScaledLeftOffsetDouble(); @@ -1216,7 +1211,7 @@ public: double dcr = clip[2] == 0 ? INT_MAX : dx + w - clip[2] - texture->GetScaledLeftOffsetDouble(); double dcb = clip[3] == 0 ? INT_MAX : dy + h - clip[3] - texture->GetScaledTopOffsetDouble(); - if(Scaled) + if(wrapper->Scaled) { if(clip[0] != 0 || clip[1] != 0) { @@ -1432,8 +1427,8 @@ public: int barW = wrapper->HorizontalResolution, barH = wrapper->VerticalResolution; rx += wrapper->ST_X; - ry += wrapper->ST_Y - (Scaled ? barH : 200) + script->height; - if(Scaled) + ry += wrapper->ST_Y - (wrapper->Scaled ? barH : 200) + script->height; + if(wrapper->Scaled) screen->VirtualToRealCoords(rx, ry, rw, rh, barW, barH, true); else { @@ -1497,7 +1492,6 @@ public: unsigned int invBarOffset; player_t *CPlayer = nullptr; DBaseStatusBar *wrapper; - bool Scaled; private: SBarInfo *script; @@ -1521,7 +1515,7 @@ void SBarInfoMainBlock::DrawAux(const SBarInfoMainBlock *block, DSBarInfo *statu rescale = true; statusBar->wrapper->ForceHUDScale(true); } - else if(!statusBar->Scaled) + else if(!statusBar->wrapper->Scaled) { rescale = true; statusBar->wrapper->SetScaled(true, true); @@ -1556,14 +1550,6 @@ DEFINE_ACTION_FUNCTION(DSBarInfo, Destroy) return 0; } -DEFINE_ACTION_FUNCTION(DSBarInfo, SetScaled) -{ - PARAM_SELF_STRUCT_PROLOGUE(DSBarInfo); - PARAM_BOOL(scale); - self->_SetScaled(scale); - return 0; -} - DEFINE_ACTION_FUNCTION(DSBarInfo, AttachToPlayer) { PARAM_SELF_STRUCT_PROLOGUE(DSBarInfo); @@ -1620,7 +1606,7 @@ DBaseStatusBar *CreateCustomStatusBar(int scriptno) auto core = new DSBarInfo(sbar, script); sbar->PointerVar("core") = core; sbar->SetSize(script->height, script->_resW, script->_resH); - core->_SetScaled(sbar->Scaled); + sbar->SetScaled(sbar->Scaled); sbar->CompleteBorder = script->completeBorder; return sbar; } diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index 2a178a249..4b70717b1 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -8816,15 +8816,20 @@ FxExpression *FxVMFunctionCall::Resolve(FCompileContext& ctx) ArgList[i] = ArgList[i]->Resolve(ctx); // nust be resolved before the address is requested. if (ArgList[i] != nullptr && ArgList[i]->ValueType != TypeNullPtr) { - if (type != ArgList[i]->ValueType) + if (type == ArgList[i]->ValueType && type->IsA(RUNTIME_CLASS(PPointer)) && static_cast(type)->IsA(RUNTIME_CLASS(PStruct))) + { + // trying to pass a struct reference as a struct refg + } + else { ArgList[i]->RequestAddress(ctx, &writable); if (flag & VARF_Ref)ArgList[i]->ValueType = NewPointer(ArgList[i]->ValueType); } + // For a reference argument the types must match 100%. if (type != ArgList[i]->ValueType) { - ScriptPosition.Message(MSG_ERROR, "Type mismatch in reference argument %s: %s != %s", Function->SymbolName.GetChars(), type->DescriptiveName(), ArgList[i]->ValueType->DescriptiveName()); + ScriptPosition.Message(MSG_ERROR, "Type mismatch in reference argument %s", Function->SymbolName.GetChars()); x = nullptr; } else diff --git a/wadsrc/static/zscript/statusbar/sbarinfowrapper.txt b/wadsrc/static/zscript/statusbar/sbarinfowrapper.txt index 8c8c6bf53..7a7aaea4f 100644 --- a/wadsrc/static/zscript/statusbar/sbarinfowrapper.txt +++ b/wadsrc/static/zscript/statusbar/sbarinfowrapper.txt @@ -1,7 +1,6 @@ struct SBarInfo native ui { - native void SetScaled(bool scaled); native void Destroy(); native void AttachToPlayer(PlayerInfo player); native void Draw(int state); @@ -25,12 +24,6 @@ class SBarInfoWrapper : BaseStatusBar Super.OnDestroy(); } - override void SetScaled(bool scale, bool force) - { - Super.SetScaled(scale, force); - core.SetScaled(Scaled); - } - override void AttachToPlayer(PlayerInfo player) { Super.AttachToPlayer(player); From 054d9a5bcc2bc7907fb8a6cd764c66b43234ba6a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Mar 2017 00:43:12 +0200 Subject: [PATCH 06/11] - allow passing the activator to ScriptCall. --- src/p_acs.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 406b5ae19..d380bbac2 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -5345,7 +5345,7 @@ static int SwapActorTeleFog(AActor *activator, int tid) return count; } -static int ScriptCall(unsigned argc, int32_t *args) +static int ScriptCall(AActor *activator, unsigned argc, int32_t *args) { int retval = 0; if (argc >= 2) @@ -5372,13 +5372,19 @@ static int ScriptCall(unsigned argc, int32_t *args) // Note that this array may not be reallocated so its initial size must be the maximum possible elements. TArray strings(argc); TArray params; + int p = 1; + if (func->Proto->ArgumentTypes.Size() > 0 && func->Proto->ArgumentTypes[0] == NewPointer(RUNTIME_CLASS(AActor))) + { + params.Push(activator); + p = 0; + } for (unsigned i = 2; i < argc; i++) { - if (func->Proto->ArgumentTypes.Size() < i - 1) + if (func->Proto->ArgumentTypes.Size() < i - p) { I_Error("Too many parameters in call to %s.%s", clsname, funcname); } - auto argtype = func->Proto->ArgumentTypes[i - 2]; + auto argtype = func->Proto->ArgumentTypes[i - p - 1]; // The only types allowed are int, bool, double, Name, Sound, Color and String if (argtype == TypeSInt32 || argtype == TypeColor) { @@ -6810,7 +6816,7 @@ doplaysound: if (funcIndex == ACSF_PlayActorSound) return (args[0] + 32768) & ~0xffff; case ACSF_ScriptCall: - return ScriptCall(argCount, args); + return ScriptCall(activator, argCount, args); case ACSF_StartSlideshow: G_StartSlideshow(FName(FBehavior::StaticLookupString(args[0]))); From d160424aea5f0a0bb77d492de69bfb5a00adb850 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Wed, 29 Mar 2017 00:45:53 +0200 Subject: [PATCH 07/11] - added DFrameBuffer::HasBegun2D to allow scripting to test if 2D drawing is active (instead of using IsLocked, which may return false when vid_hw2d is active) --- src/g_statusbar/shared_sbar.cpp | 8 ++++---- src/gl/system/gl_swframebuffer.h | 2 +- src/v_draw.cpp | 6 +++--- src/v_text.cpp | 4 ++-- src/v_video.h | 3 +++ src/win32/win32swiface.h | 1 + 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index 229cfb5e0..b22b48cf2 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -1700,7 +1700,7 @@ DEFINE_ACTION_FUNCTION(DBaseStatusBar, DrawTexture) PARAM_FLOAT_DEF(h); PARAM_FLOAT_DEF(scaleX); PARAM_FLOAT_DEF(scaleY); - if (!screen->IsLocked()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); + if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); self->DrawGraphic(FSetTextureID(texid), x, y, flags, alpha, w, h, scaleX, scaleY); return 0; } @@ -1717,7 +1717,7 @@ DEFINE_ACTION_FUNCTION(DBaseStatusBar, DrawImage) PARAM_FLOAT_DEF(h); PARAM_FLOAT_DEF(scaleX); PARAM_FLOAT_DEF(scaleY); - if (!screen->IsLocked()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); + if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); self->DrawGraphic(TexMan.CheckForTexture(texid, FTexture::TEX_Any), x, y, flags, alpha, w, h, scaleX, scaleY); return 0; } @@ -1910,7 +1910,7 @@ DEFINE_ACTION_FUNCTION(DBaseStatusBar, DrawString) PARAM_INT_DEF(wrapwidth); PARAM_INT_DEF(linespacing); - if (!screen->IsLocked()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); + if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); // resolve auto-alignment before making any adjustments to the position values. if (!(flags & DI_SCREEN_MANUAL_ALIGN)) @@ -2015,7 +2015,7 @@ DEFINE_ACTION_FUNCTION(DBaseStatusBar, Fill) PARAM_FLOAT(w); PARAM_FLOAT(h); PARAM_INT_DEF(flags); - if (!screen->IsLocked()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); + if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); self->Fill(color, x, y, w, h); return 0; } diff --git a/src/gl/system/gl_swframebuffer.h b/src/gl/system/gl_swframebuffer.h index 03cc5a4e0..04f961493 100644 --- a/src/gl/system/gl_swframebuffer.h +++ b/src/gl/system/gl_swframebuffer.h @@ -33,7 +33,7 @@ public: OpenGLSWFrameBuffer(void *hMonitor, int width, int height, int bits, int refreshHz, bool fullscreen, bool bgra); ~OpenGLSWFrameBuffer(); - + bool HasBegun2D() override { return In2D || IsLocked(); } bool IsValid() override; bool Lock(bool buffered) override; void Unlock() override; diff --git a/src/v_draw.cpp b/src/v_draw.cpp index a45cbddac..b95ade5bd 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -137,7 +137,7 @@ DEFINE_ACTION_FUNCTION(_Screen, DrawTexture) PARAM_FLOAT(x); PARAM_FLOAT(y); - if (!screen->IsLocked()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); + if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); FTexture *tex = animate ? TexMan(FSetTextureID(texid)) : TexMan[FSetTextureID(texid)]; VMVa_List args = { param + 4, 0, numparam - 4 }; @@ -961,7 +961,7 @@ DEFINE_ACTION_FUNCTION(_Screen, Clear) PARAM_INT(y2); PARAM_INT(color); PARAM_INT_DEF(palcol); - if (!screen->IsLocked()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); + if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); screen->Clear(x1, y1, x2, y2, palcol, color); return 0; } @@ -1013,7 +1013,7 @@ DEFINE_ACTION_FUNCTION(_Screen, Dim) PARAM_INT(y1); PARAM_INT(w); PARAM_INT(h); - if (!screen->IsLocked()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); + if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); screen->Dim(color, float(amount), x1, y1, w, h); return 0; } diff --git a/src/v_text.cpp b/src/v_text.cpp index fa04da365..90131ed86 100644 --- a/src/v_text.cpp +++ b/src/v_text.cpp @@ -116,7 +116,7 @@ DEFINE_ACTION_FUNCTION(_Screen, DrawChar) PARAM_FLOAT(y); PARAM_INT(chr); - if (!screen->IsLocked()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); + if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); VMVa_List args = { param + 5, 0, numparam - 5 }; screen->DrawChar(font, cr, x, y, chr, args); return 0; @@ -242,7 +242,7 @@ DEFINE_ACTION_FUNCTION(_Screen, DrawText) PARAM_FLOAT(y); PARAM_STRING(chr); - if (!screen->IsLocked()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); + if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); VMVa_List args = { param + 5, 0, numparam - 5 }; const char *txt = chr[0] == '$' ? GStrings(&chr[1]) : chr.GetChars(); screen->DrawText(font, cr, x, y, txt, args); diff --git a/src/v_video.h b/src/v_video.h index 56041a228..2d554dea9 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -410,6 +410,9 @@ public: // Returns true if hardware-accelerated 2D has been entered, false if not. virtual bool Begin2D(bool copy3d); + // Returns true if Begin2D has been called and 2D drawing is now active + virtual bool HasBegun2D() { return IsLocked(); } + // DrawTexture calls after Begin2D use native textures. // Draws the blending rectangle over the viewwindow if in hardware- diff --git a/src/win32/win32swiface.h b/src/win32/win32swiface.h index 5c0a456e4..7cf8728e0 100644 --- a/src/win32/win32swiface.h +++ b/src/win32/win32swiface.h @@ -105,6 +105,7 @@ public: D3DFB (UINT adapter, int width, int height, bool bgra, bool fullscreen); ~D3DFB (); + bool HasBegun2D() override { return In2D || IsLocked(); } bool IsValid (); bool Lock (bool buffered); void Unlock (); From 3a569f176dc973e2c9735d0b65de0cacd3cfee2c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Mar 2017 01:01:40 +0200 Subject: [PATCH 08/11] - added GetLineX/GetLineY ACS functions. --- src/p_acs.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/p_acs.cpp b/src/p_acs.cpp index d380bbac2..f9e0f58e7 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -4964,6 +4964,10 @@ enum EACSFunctions ACSF_ScriptCall, ACSF_StartSlideshow, + // Eternity's + ACSF_GetLineX = 300, + ACSF_GetLineY, + // OpenGL stuff ACSF_SetSectorGlow = 400, @@ -6822,11 +6826,24 @@ doplaysound: if (funcIndex == ACSF_PlayActorSound) G_StartSlideshow(FName(FBehavior::StaticLookupString(args[0]))); break; + case ACSF_GetLineX: + case ACSF_GetLineY: + { + FLineIdIterator it(args[0]); + int lineno = it.Next(); + if (lineno < 0) return 0; + DVector2 delta = level.lines[lineno].Delta(); + double result = delta[funcIndex - ACSF_GetLineX] * ACSToDouble(args[1]); + if (args[2]) + { + DVector2 normal = DVector2(delta.Y, -delta.X).Unit(); + result += normal[funcIndex - ACSF_GetLineX] * ACSToDouble(args[2]); + } + return DoubleToACS(result); + } default: break; } - - return 0; } From 914c829f798fffa2b0ea25e5a061936073ae9966 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Mar 2017 01:25:02 +0200 Subject: [PATCH 09/11] - added Floor/Ceiling_MoveToValueAndCrush action specials. --- src/actionspecials.h | 4 ++++ src/p_lnspec.cpp | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/actionspecials.h b/src/actionspecials.h index 173a07b2d..08f989754 100644 --- a/src/actionspecials.h +++ b/src/actionspecials.h @@ -262,5 +262,9 @@ DEFINE_SPECIAL(Stairs_BuildUpDoomCrush, 273, 5, 5, 5) DEFINE_SPECIAL(Door_AnimatedClose, 274, 4, 4, 4) DEFINE_SPECIAL(Floor_Stop, 275, 1, 1, 1) DEFINE_SPECIAL(Ceiling_Stop, 276, 1, 1, 1) +DEFINE_SPECIAL(Sector_SetFloorGlow, 277, 5, 5, 5) +DEFINE_SPECIAL(Sector_SetCeilingGlow, 278, 5, 5, 5) +DEFINE_SPECIAL(Floor_MoveToValueAndCrush, 279, 4, 5, 5) +DEFINE_SPECIAL(Ceiling_MoveToValueAndCrush, 290, 4, 5, 5) #undef DEFINE_SPECIAL diff --git a/src/p_lnspec.cpp b/src/p_lnspec.cpp index 1271e7603..39b97f1d8 100644 --- a/src/p_lnspec.cpp +++ b/src/p_lnspec.cpp @@ -451,6 +451,13 @@ FUNC(LS_Floor_MoveToValue) arg2*(arg3?-1:1), -1, CHANGE(arg4), false); } +FUNC(LS_Floor_MoveToValueAndCrush) +// Floor_MoveToValueAndCrush (tag, speed, height, crush, crushmode) +{ + return EV_DoFloor(DFloor::floorMoveToValue, ln, arg0, SPEED(arg1), + arg2, CRUSH(arg3) -1, 0, CRUSHTYPE(arg4), false); +} + FUNC(LS_Floor_RaiseToLowestCeiling) // Floor_RaiseToLowestCeiling (tag, speed, change, crush) { @@ -744,6 +751,13 @@ FUNC(LS_Ceiling_MoveToValue) arg2*((arg3) ? -1 : 1), -1, 0, CHANGE(arg4)); } +FUNC(LS_Ceiling_MoveToValueAndCrush) +// Ceiling_MoveToValueAndCrush (tag, speed, height, crush, crushmode) +{ + return EV_DoCeiling (DCeiling::ceilMoveToValue, ln, arg0, SPEED(arg1), 0, + arg2, CRUSH(arg3), 0, 0, CRUSHTYPE(arg4, arg1 == 8)); +} + FUNC(LS_Ceiling_LowerToHighestFloor) // Ceiling_LowerToHighestFloor (tag, speed, change, crush, gap) { @@ -855,13 +869,13 @@ FUNC(LS_Ceiling_ToFloorInstant) FUNC(LS_Ceiling_LowerToFloor) // Ceiling_LowerToFloor (tag, speed, change, crush, gap) { - return EV_DoCeiling (DCeiling::ceilLowerToFloor, ln, arg0, SPEED(arg1), 0, arg4, CRUSH(arg3), 0, CHANGE(arg4)); + return EV_DoCeiling (DCeiling::ceilLowerToFloor, ln, arg0, SPEED(arg1), 0, arg4, CRUSH(arg3), 0, CHANGE(arg2)); } FUNC(LS_Ceiling_LowerByTexture) // Ceiling_LowerByTexture (tag, speed, change, crush) { - return EV_DoCeiling (DCeiling::ceilLowerByTexture, ln, arg0, SPEED(arg1), 0, 0, CRUSH(arg3), 0, CHANGE(arg4)); + return EV_DoCeiling (DCeiling::ceilLowerByTexture, ln, arg0, SPEED(arg1), 0, 0, CRUSH(arg3), 0, CHANGE(arg2)); } FUNC(LS_Ceiling_Stop) @@ -3702,6 +3716,8 @@ static lnSpecFunc LineSpecials[] = /* 276 */ LS_Ceiling_Stop, /* 277 */ LS_Sector_SetFloorGlow, /* 278 */ LS_Sector_SetCeilingGlow, + /* 279 */ LS_Floor_MoveToValueAndCrush, + /* 280 */ LS_Ceiling_MoveToValueAndCrush, }; From 598523a1ded352283b426735315095831d61d1e8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Mar 2017 01:59:03 +0200 Subject: [PATCH 10/11] - moved all coordinate adjustment for the status bar mode into one function and use this function in all places where status bar related coordinate adjustments need to be performed, also in SBARINFO. - fixed unscaled status bar placement. - fixed inventory count display for Doom status bar. --- src/g_statusbar/sbar.h | 2 + src/g_statusbar/sbarinfo.cpp | 36 ++++----------- src/g_statusbar/shared_sbar.cpp | 46 +++++++++---------- wadsrc/static/zscript/statusbar/doom_sbar.txt | 2 +- 4 files changed, 33 insertions(+), 53 deletions(-) diff --git a/src/g_statusbar/sbar.h b/src/g_statusbar/sbar.h index d7c771767..3ac2681f1 100644 --- a/src/g_statusbar/sbar.h +++ b/src/g_statusbar/sbar.h @@ -402,6 +402,7 @@ public: void BeginStatusBar(int resW, int resH, int relTop, bool completeborder = false, bool forceScaled = false); void BeginHUD(int resW, int resH, double Alpha, bool forceScaled = false); void ForceHUDScale(bool on) { ForcedScale = on; } // This is for SBARINFO which should not use BeginStatusBar or BeginHUD. + void StatusbarToRealCoords(double &x, double &y, double &w, double &h) const; //protected: void DrawPowerups (); @@ -410,6 +411,7 @@ public: void RefreshBackground () const; public: + AInventory *ValidateInvFirst (int numVisible) const; void DrawCrosshair (); diff --git a/src/g_statusbar/sbarinfo.cpp b/src/g_statusbar/sbarinfo.cpp index 9f069b831..8c775dd84 100644 --- a/src/g_statusbar/sbarinfo.cpp +++ b/src/g_statusbar/sbarinfo.cpp @@ -1200,10 +1200,6 @@ public: if(!fullScreenOffsets) { double tmp = 0; - int barW = wrapper->HorizontalResolution, barH = wrapper->VerticalResolution; - - dx += wrapper->ST_X; - dy += wrapper->ST_Y - (wrapper->Scaled ? barH : 200) + script->height; w = forceWidth < 0 ? texture->GetScaledWidthDouble() : forceWidth; h = forceHeight < 0 ? texture->GetScaledHeightDouble() : forceHeight; double dcx = clip[0] == 0 ? 0 : dx + clip[0] - texture->GetScaledLeftOffsetDouble(); @@ -1211,24 +1207,17 @@ public: double dcr = clip[2] == 0 ? INT_MAX : dx + w - clip[2] - texture->GetScaledLeftOffsetDouble(); double dcb = clip[3] == 0 ? INT_MAX : dy + h - clip[3] - texture->GetScaledTopOffsetDouble(); - if(wrapper->Scaled) + if(clip[0] != 0 || clip[1] != 0) { - if(clip[0] != 0 || clip[1] != 0) - { - screen->VirtualToRealCoords(dcx, dcy, tmp, tmp, barW, barH, true); - if (clip[0] == 0) dcx = 0; - if (clip[1] == 0) dcy = 0; - } - if(clip[2] != 0 || clip[3] != 0 || clearDontDraw) - screen->VirtualToRealCoords(dcr, dcb, tmp, tmp, barW, barH, true); - screen->VirtualToRealCoords(dx, dy, w, h, barW, barH, true); + wrapper->StatusbarToRealCoords(dcx, dcy, tmp, tmp); + if (clip[0] == 0) dcx = 0; + if (clip[1] == 0) dcy = 0; } - else + if (clip[2] != 0 || clip[3] != 0 || clearDontDraw) { - dy += 200 - barH; - dcy += 200 - barH; - dcb += 200 - barH; + wrapper->StatusbarToRealCoords(dcr, dcb, tmp, tmp); } + wrapper->StatusbarToRealCoords(dx, dy, w, h); if(clearDontDraw) screen->Clear(static_cast(MAX(dx, dcx)), static_cast(MAX(dy, dcy)), static_cast(MIN(dcr,w+MAX(dx, dcx))), static_cast(MIN(dcb,MAX(dy, dcy)+h)), GPalette.BlackIndex, 0); @@ -1424,16 +1413,7 @@ public: if(!fullScreenOffsets) { - - int barW = wrapper->HorizontalResolution, barH = wrapper->VerticalResolution; - rx += wrapper->ST_X; - ry += wrapper->ST_Y - (wrapper->Scaled ? barH : 200) + script->height; - if(wrapper->Scaled) - screen->VirtualToRealCoords(rx, ry, rw, rh, barW, barH, true); - else - { - ry += (200 - barH); - } + wrapper->StatusbarToRealCoords(rx, ry, rw, rh); } else { diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index b22b48cf2..3bced97dc 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -1564,6 +1564,25 @@ uint32_t DBaseStatusBar::GetTranslation() const // //============================================================================ +void DBaseStatusBar::StatusbarToRealCoords(double &x, double &y, double &w, double &h) const +{ + if (Scaled) + { + screen->VirtualToRealCoords(x, y, w, h, HorizontalResolution, VerticalResolution, true, true); + } + else + { + x += ST_X; + y += screen->GetHeight() - VerticalResolution; + } +} + +//============================================================================ +// +// draw stuff +// +//============================================================================ + void DBaseStatusBar::DrawGraphic(FTextureID texture, double x, double y, int flags, double Alpha, double boxwidth, double boxheight, double scaleX, double scaleY) { if (!texture.isValid()) @@ -1636,14 +1655,7 @@ void DBaseStatusBar::DrawGraphic(FTextureID texture, double x, double y, int fla if (!fullscreenOffsets) { - x += ST_X; - //y += ST_Y; - - // Todo: Allow other scaling values, too. - if (Scaled) - { - screen->VirtualToRealCoords(x, y, boxwidth, boxheight, HorizontalResolution, VerticalResolution, true, true); - } + StatusbarToRealCoords(x, y, boxwidth, boxheight); } else { @@ -1853,14 +1865,7 @@ void DBaseStatusBar::DrawString(FFont *font, const FString &cstring, double x, d if (!fullscreenOffsets) { - rx += ST_X; - //ry += ST_Y; - - // Todo: Allow other scaling values, too. - if (Scaled) - { - screen->VirtualToRealCoords(rx, ry, rw, rh, HorizontalResolution, VerticalResolution, true); - } + StatusbarToRealCoords(rx, ry, rw, rh); } else { @@ -1963,14 +1968,7 @@ void DBaseStatusBar::Fill(PalEntry color, double x, double y, double w, double h if (!fullscreenOffsets) { - x += ST_X; - //y += ST_Y; - - // Todo: Allow other scaling values, too. - if (Scaled) - { - screen->VirtualToRealCoords(x, y, w, h, HorizontalResolution, VerticalResolution, true, true); - } + StatusbarToRealCoords(x, y, w, h); } else { diff --git a/wadsrc/static/zscript/statusbar/doom_sbar.txt b/wadsrc/static/zscript/statusbar/doom_sbar.txt index 67ea2c620..b1671889a 100644 --- a/wadsrc/static/zscript/statusbar/doom_sbar.txt +++ b/wadsrc/static/zscript/statusbar/doom_sbar.txt @@ -110,7 +110,7 @@ class DoomStatusBar : BaseStatusBar if (CPlayer.mo.InvSel != null && !level.NoInventoryBar) { DrawInventoryIcon(CPlayer.mo.InvSel, (160, 198)); - if (CPlayer.mo.InvSel.Amount > 0) + if (CPlayer.mo.InvSel.Amount > 1) { DrawString(mAmountFont, FormatNumber(CPlayer.mo.InvSel.Amount), (175, 198-mIndexFont.mFont.GetHeight()), DI_TEXT_ALIGN_RIGHT, Font.CR_GOLD); } From fabf8451e7690fd36cd1e49ed5c3b9b516a0abad Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Mar 2017 02:24:04 +0200 Subject: [PATCH 11/11] - use Fill to draw Strife's health bars. --- src/g_statusbar/shared_sbar.cpp | 7 ++++- .../static/zscript/statusbar/strife_sbar.txt | 29 +++++++------------ 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index 3bced97dc..f6b0644cc 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -2000,7 +2000,12 @@ void DBaseStatusBar::Fill(PalEntry color, double x, double y, double w, double h x += orgx; y += orgy; } - screen->Dim(color, float(Alpha), int(x), int(y), int(w), int(h)); + int x1 = int(x); + int y1 = int(y); + int ww = int(x + w - x1); // account for scaling to non-integers. Truncating the values separately would fail for cases like + int hh = int(y + h - y1); // y=3.5, height = 5.5 where adding both values gives a larger integer than adding the two integers. + + screen->Dim(color, float(Alpha), x1, y1, ww, hh); } diff --git a/wadsrc/static/zscript/statusbar/strife_sbar.txt b/wadsrc/static/zscript/statusbar/strife_sbar.txt index fc1862698..148b1e237 100644 --- a/wadsrc/static/zscript/statusbar/strife_sbar.txt +++ b/wadsrc/static/zscript/statusbar/strife_sbar.txt @@ -202,32 +202,23 @@ class StrifeStatusBar : BaseStatusBar private void FillBar(double x, double y, double start, double stopp, Color color1, Color color2) { - Vector2 virt = Scaled? (320., 200.) : (screen.GetWidth(), screen.GetHeight()); - Vector2 pos, sizev; - - start *=2; - stopp *=2; - - [pos, sizev] = screen.VirtualToRealCoords((ST_X + x + start, ST_Y + y), (stopp - start, 1), virt, true, Scaled); - screen.Dim(color1, 1.0, pos.X + 0.5, pos.Y + 0.5, sizev.X + 0.5, sizev.Y + 0.5); - - [pos, sizev] = screen.VirtualToRealCoords((ST_X + x + start, ST_Y + y + 1), (stopp - start, 1), virt, true, Scaled); - screen.Dim(color2, 1.0, pos.X + 0.5, pos.Y + 0.5, sizev.X + 0.5, sizev.Y + 0.5); + Fill(color1, x, y, (stopp-start)*2, 1); + Fill(color2, x, y+1, (stopp-start)*2, 1); } protected void DrawHealthBar(int health, int x, int y) { - Color green1 = Color(180, 228, 128); // light green - Color green2 = Color(128, 180, 80); // dark green + Color green1 = Color(255, 180, 228, 128); // light green + Color green2 = Color(255, 128, 180, 80); // dark green - Color blue1 = Color(196, 204, 252); // light blue - Color blue2 = Color(148, 152, 200); // dark blue + Color blue1 = Color(255, 196, 204, 252); // light blue + Color blue2 = Color(255, 148, 152, 200); // dark blue - Color gold1 = Color(224, 188, 0); // light gold - Color gold2 = Color(208, 128, 0); // dark gold + Color gold1 = Color(255, 224, 188, 0); // light gold + Color gold2 = Color(255, 208, 128, 0); // dark gold - Color red1 = Color(216, 44, 44); // light red - Color red2 = Color(172, 28, 28); // dark red + Color red1 = Color(255, 216, 44, 44); // light red + Color red2 = Color(255, 172, 28, 28); // dark red if (health == 999) {