diff --git a/src/actor.h b/src/actor.h index 00532fb65..0277eabe4 100644 --- a/src/actor.h +++ b/src/actor.h @@ -975,7 +975,7 @@ public: { SetOrigin(Pos() + vel, true); } - void SetOrigin(double x, double y, double z, bool moving); + virtual void SetOrigin(double x, double y, double z, bool moving); void SetOrigin(const DVector3 & npos, bool moving) { SetOrigin(npos.X, npos.Y, npos.Z, moving); diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 870af02dd..c29a0dd6c 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -867,6 +867,14 @@ sector_t * FGLRenderer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, flo // This should be done after postprocessing, not before. mBuffers->BindCurrentFB(); glViewport(mScreenViewport.left, mScreenViewport.top, mScreenViewport.width, mScreenViewport.height); + + if (!toscreen) + { + gl_RenderState.mViewMatrix.loadIdentity(); + gl_RenderState.mProjectionMatrix.ortho(mScreenViewport.left, mScreenViewport.width, mScreenViewport.height, mScreenViewport.top, -1.0f, 1.0f); + gl_RenderState.ApplyMatrices(); + } + DrawBlend(lviewsector); } mDrawingScene2D = false; diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 25cf35059..76071f895 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -3197,6 +3197,7 @@ void P_NightmareRespawn (AActor *mobj) // spawn it mo = AActor::StaticSpawn(mobj->GetClass(), DVector3(mobj->SpawnPoint.X, mobj->SpawnPoint.Y, z), NO_REPLACE, true); + mo->health = mobj->SpawnHealth(); if (z == ONFLOORZ) { diff --git a/src/scripting/thingdef_data.cpp b/src/scripting/thingdef_data.cpp index 218fc7bc4..80ae773cc 100644 --- a/src/scripting/thingdef_data.cpp +++ b/src/scripting/thingdef_data.cpp @@ -1136,4 +1136,48 @@ DEFINE_ACTION_FUNCTION(FStringStruct, AppendFormat) FString s = FStringFormat(param+1, defaultparam, numparam-1, ret, numret); (*self) += s; return 0; -} \ No newline at end of file +} + +DEFINE_ACTION_FUNCTION(FStringStruct, Mid) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + PARAM_INT(pos); + PARAM_INT(len); + // validate. we don't want to crash if someone passes negative values. + // with size_t it's handled naturally I think, as it's unsigned, but not in ZScript. + if (pos < 0) pos = 0; + if (len < 0) len = 0; + int slen = self->Len(); + if (pos > slen) pos = slen - 1; + if (pos + len > slen) + len = slen - pos; + FString s = self->Mid(pos, len); + ACTION_RETURN_STRING(s); +} + +DEFINE_ACTION_FUNCTION(FStringStruct, Len) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + ACTION_RETURN_INT(self->Len()); +} + +// CharAt and CharCodeAt is how JS does it, and JS is similar here in that it doesn't have char type as int. +DEFINE_ACTION_FUNCTION(FStringStruct, CharAt) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + PARAM_INT(pos); + int slen = self->Len(); + if (pos < 0 || pos >= slen) + ACTION_RETURN_STRING(""); + ACTION_RETURN_STRING(FString((*self)[pos])); +} + +DEFINE_ACTION_FUNCTION(FStringStruct, CharCodeAt) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + PARAM_INT(pos); + int slen = self->Len(); + if (pos < 0 || pos >= slen) + ACTION_RETURN_INT(0); + ACTION_RETURN_INT((*self)[pos]); +} diff --git a/src/v_draw.cpp b/src/v_draw.cpp index 52f8cde7a..6f0e8330a 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -129,12 +129,12 @@ static int PalFromRGB(uint32 rgb) void DCanvas::DrawTexture (FTexture *img, double x, double y, int tags_first, ...) { - va_list tags; - va_start(tags, tags_first); + Va_List tags; + va_start(tags.list, tags_first); DrawParms parms; bool res = ParseDrawTextureTags(img, x, y, tags_first, tags, &parms, false); - va_end(tags); + va_end(tags.list); if (!res) { return; @@ -457,30 +457,30 @@ bool DCanvas::SetTextureParms(DrawParms *parms, FTexture *img, double xx, double return false; } -static void ListEnd(va_list &tags) +static void ListEnd(Va_List &tags) { - va_end(tags); + va_end(tags.list); } -static int ListGetInt(va_list &tags) +static int ListGetInt(Va_List &tags) { - return va_arg(tags, int); + return va_arg(tags.list, int); } -static inline double ListGetDouble(va_list &tags) +static inline double ListGetDouble(Va_List &tags) { - return va_arg(tags, double); + return va_arg(tags.list, double); } // These two options are only being used by the D3D version of the HUD weapon drawer, they serve no purpose anywhere else. -static inline FSpecialColormap * ListGetSpecialColormap(va_list &tags) +static inline FSpecialColormap * ListGetSpecialColormap(Va_List &tags) { - return va_arg(tags, FSpecialColormap *); + return va_arg(tags.list, FSpecialColormap *); } -static inline FColormapStyle * ListGetColormapStyle(va_list &tags) +static inline FColormapStyle * ListGetColormapStyle(Va_List &tags) { - return va_arg(tags, FColormapStyle *); + return va_arg(tags.list, FColormapStyle *); } static void ListEnd(VMVa_List &tags) @@ -946,7 +946,7 @@ bool DCanvas::ParseDrawTextureTags(FTexture *img, double x, double y, DWORD tag, } // explicitly instantiate both versions for v_text.cpp. -template bool DCanvas::ParseDrawTextureTags(FTexture *img, double x, double y, DWORD tag, va_list& tags, DrawParms *parms, bool fortext) const; +template bool DCanvas::ParseDrawTextureTags(FTexture *img, double x, double y, DWORD tag, Va_List& tags, DrawParms *parms, bool fortext) const; template bool DCanvas::ParseDrawTextureTags(FTexture *img, double x, double y, DWORD tag, VMVa_List& tags, DrawParms *parms, bool fortext) const; void DCanvas::VirtualToRealCoords(double &x, double &y, double &w, double &h, diff --git a/src/v_text.cpp b/src/v_text.cpp index 3394e448a..8b612e83c 100644 --- a/src/v_text.cpp +++ b/src/v_text.cpp @@ -71,10 +71,10 @@ void DCanvas::DrawChar (FFont *font, int normalcolor, double x, double y, int ch if (NULL != (pic = font->GetChar (character, &dummy))) { DrawParms parms; - va_list tags; - va_start(tags, tag_first); + Va_List tags; + va_start(tags.list, tag_first); bool res = ParseDrawTextureTags(pic, x, y, tag_first, tags, &parms, false); - va_end(tags); + va_end(tags.list); if (!res) { return; @@ -197,15 +197,15 @@ void DCanvas::DrawTextCommon(FFont *font, int normalcolor, double x, double y, c void DCanvas::DrawText(FFont *font, int normalcolor, double x, double y, const char *string, int tag_first, ...) { - va_list tags; + Va_List tags; DrawParms parms; if (font == NULL || string == NULL) return; - va_start(tags, tag_first); + va_start(tags.list, tag_first); bool res = ParseDrawTextureTags(nullptr, 0, 0, tag_first, tags, &parms, true); - va_end(tags); + va_end(tags.list); if (!res) { return; diff --git a/src/v_video.cpp b/src/v_video.cpp index 6077f878e..6d5913ce1 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -1396,7 +1396,7 @@ void V_CalcCleanFacs (int designwidth, int designheight, int realwidth, int real cy1 = MAX(cheight / designheight, 1); cx2 = MAX(realwidth / designwidth, 1); cy2 = MAX(realheight / designheight, 1); - if (abs(cx1 - cy1) <= abs(cx2 - cy2)) + if (abs(cx1 - cy1) <= abs(cx2 - cy2) || cx1 >= 4) { // e.g. 640x360 looks better with this. *cleanx = cx1; *cleany = cy1; diff --git a/src/v_video.h b/src/v_video.h index a594fa8fe..a2586d5a7 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -177,6 +177,11 @@ struct DrawParms bool virtBottom; }; +struct Va_List +{ + va_list list; +}; + struct VMVa_List { VMValue *args; diff --git a/wadsrc/static/zscript/base.txt b/wadsrc/static/zscript/base.txt index 20ce0f2a7..c89f6244b 100644 --- a/wadsrc/static/zscript/base.txt +++ b/wadsrc/static/zscript/base.txt @@ -418,9 +418,14 @@ enum EPickStart // Although String is a builtin type, this is a convenient way to attach methods to it. struct StringStruct native { - native void Replace(String pattern, String replacement); native static vararg String Format(String fmt, ...); native vararg void AppendFormat(String fmt, ...); + + native void Replace(String pattern, String replacement); + native String Mid(int pos = 0, int len = 2147483647); + native int Len(); + native String CharAt(int pos); + native int CharCodeAt(int pos); } class Floor : Thinker native