diff --git a/src/p_actionfunctions.cpp b/src/p_actionfunctions.cpp index 43c9e45fe0..e863a442c5 100644 --- a/src/p_actionfunctions.cpp +++ b/src/p_actionfunctions.cpp @@ -1892,7 +1892,7 @@ EXTERN_CVAR(Float, con_midtime) DEFINE_ACTION_FUNCTION(AActor, A_Print) { PARAM_SELF_PROLOGUE(AActor); - PARAM_STRING (text); + PARAM_STRING_VAL(text); PARAM_FLOAT (time); PARAM_NAME (fontname); @@ -1927,7 +1927,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_Print) DEFINE_ACTION_FUNCTION(AActor, A_PrintBold) { PARAM_SELF_PROLOGUE(AActor); - PARAM_STRING (text); + PARAM_STRING_VAL (text); PARAM_FLOAT (time); PARAM_NAME (fontname); @@ -1958,7 +1958,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_PrintBold) DEFINE_ACTION_FUNCTION(AActor, A_Log) { PARAM_SELF_PROLOGUE(AActor); - PARAM_STRING(text); + PARAM_STRING_VAL(text); PARAM_BOOL(local); if (local && !self->CheckLocalView(consoleplayer)) return 0; diff --git a/src/scripting/thingdef.h b/src/scripting/thingdef.h index b26ddd1d78..33d9e7450e 100644 --- a/src/scripting/thingdef.h +++ b/src/scripting/thingdef.h @@ -74,7 +74,7 @@ void HandleDeprecatedFlags(AActor *defaults, PClassActor *info, bool set, int in bool CheckDeprecatedFlags(const AActor *actor, PClassActor *info, int index); const char *GetFlagName(unsigned int flagnum, int flagoffset); void ModActorFlag(AActor *actor, FFlagDef *fd, bool set); -bool ModActorFlag(AActor *actor, FString &flagname, bool set, bool printerror = true); +bool ModActorFlag(AActor *actor, const FString &flagname, bool set, bool printerror = true); INTBOOL CheckActorFlag(const AActor *actor, FFlagDef *fd); INTBOOL CheckActorFlag(const AActor *owner, const char *flagname, bool printerror = true); diff --git a/src/scripting/thingdef_properties.cpp b/src/scripting/thingdef_properties.cpp index 4d7908c6b0..a279ed070d 100644 --- a/src/scripting/thingdef_properties.cpp +++ b/src/scripting/thingdef_properties.cpp @@ -142,7 +142,7 @@ void ModActorFlag(AActor *actor, FFlagDef *fd, bool set) // //========================================================================== -bool ModActorFlag(AActor *actor, FString &flagname, bool set, bool printerror) +bool ModActorFlag(AActor *actor, const FString &flagname, bool set, bool printerror) { bool found = false; diff --git a/src/scripting/vm/vm.h b/src/scripting/vm/vm.h index 8ed78b8546..98c59eb67a 100644 --- a/src/scripting/vm/vm.h +++ b/src/scripting/vm/vm.h @@ -511,7 +511,8 @@ bool AssertObject(void * ob); #define PARAM_COLOR_AT(p,x) assert((p) < numparam); assert(reginfo[p] == REGT_INT); PalEntry x; x.d = param[p].i; #define PARAM_FLOAT_AT(p,x) assert((p) < numparam); assert(reginfo[p] == REGT_FLOAT); double x = param[p].f; #define PARAM_ANGLE_AT(p,x) assert((p) < numparam); assert(reginfo[p] == REGT_FLOAT); DAngle x = param[p].f; -#define PARAM_STRING_AT(p,x) assert((p) < numparam); assert(reginfo[p] == REGT_STRING); FString x = param[p].s(); +#define PARAM_STRING_VAL_AT(p,x) assert((p) < numparam); assert(reginfo[p] == REGT_STRING); FString x = param[p].s(); +#define PARAM_STRING_AT(p,x) assert((p) < numparam); assert(reginfo[p] == REGT_STRING); const FString &x = param[p].s(); #define PARAM_STATE_AT(p,x) assert((p) < numparam); assert(reginfo[p] == REGT_INT); FState *x = (FState *)StateLabels.GetState(param[p].i, self->GetClass()); #define PARAM_STATE_ACTION_AT(p,x) assert((p) < numparam); assert(reginfo[p] == REGT_INT); FState *x = (FState *)StateLabels.GetState(param[p].i, stateowner->GetClass()); #define PARAM_POINTER_AT(p,x,type) assert((p) < numparam); assert(reginfo[p] == REGT_POINTER); type *x = (type *)param[p].a; @@ -536,6 +537,7 @@ bool AssertObject(void * ob); #define PARAM_FLOAT(x) ++paramnum; PARAM_FLOAT_AT(paramnum,x) #define PARAM_ANGLE(x) ++paramnum; PARAM_ANGLE_AT(paramnum,x) #define PARAM_STRING(x) ++paramnum; PARAM_STRING_AT(paramnum,x) +#define PARAM_STRING_VAL(x) ++paramnum; PARAM_STRING_VAL_AT(paramnum,x) #define PARAM_STATE(x) ++paramnum; PARAM_STATE_AT(paramnum,x) #define PARAM_STATE_ACTION(x) ++paramnum; PARAM_STATE_ACTION_AT(paramnum,x) #define PARAM_POINTER(x,type) ++paramnum; PARAM_POINTER_AT(paramnum,x,type) diff --git a/src/scripting/vmthunks.cpp b/src/scripting/vmthunks.cpp index 3b9a549474..e353eaa447 100644 --- a/src/scripting/vmthunks.cpp +++ b/src/scripting/vmthunks.cpp @@ -19,6 +19,13 @@ // // VM thunks for internal functions. // +// Important note about this file: Since everything in here is supposed to be called +// from JIT-compiled VM code it needs to be very careful about calling conventions. +// As a result none of the integer sized struct types may be used as function +// arguments, because current C++ calling conventions require them to be passed +// by reference. The JIT code, however will pass them by value so any direct native function +// taking such an argument needs to receive it as a naked int. +// //----------------------------------------------------------------------------- #include "vm.h" @@ -26,7 +33,14 @@ #include "g_levellocals.h" #include "s_sound.h" #include "p_local.h" +#include "v_font.h" +#include "gstrings.h" +//===================================================================================== +// +// sector_t exports +// +//===================================================================================== DEFINE_ACTION_FUNCTION_NATIVE(_Sector, FindLowestFloorSurrounding, FindLowestFloorSurrounding) { @@ -1033,7 +1047,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Sector, RemoveForceField, RemoveForceField) //=========================================================================== // - // + // side_t exports // //=========================================================================== @@ -1281,6 +1295,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Sector, RemoveForceField, RemoveForceField) //===================================================================================== // + // vertex_t exports // //===================================================================================== @@ -1300,6 +1315,12 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Sector, RemoveForceField, RemoveForceField) ACTION_RETURN_INT(VertexIndex(self)); } + //===================================================================================== +// +// TexMan exports +// +//===================================================================================== + // This is needed to convert the strings to char pointers. static void ReplaceTextures(const FString &from, const FString &to, int flags) { @@ -1318,6 +1339,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, ReplaceTextures, ReplaceTextures) //===================================================================================== // +// secplane_t exports // //===================================================================================== @@ -1445,6 +1467,104 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Secplane, PointToDist, PointToDist) ACTION_RETURN_FLOAT(self->PointToDist(DVector2(x, y), z)); } +//===================================================================================== +// +// FFont exports +// +//===================================================================================== + +static FFont *GetFont(int name) +{ + return V_GetFont(FName(ENamedName(name)).GetChars()); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FFont, GetFont, GetFont) +{ + PARAM_PROLOGUE; + PARAM_INT(name); + ACTION_RETURN_POINTER(GetFont(name)); +} + +static FFont *FindFont(int name) +{ + return FFont::FindFont(FName(ENamedName(name))); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FFont, FindFont, FindFont) +{ + PARAM_PROLOGUE; + PARAM_NAME(name); + ACTION_RETURN_POINTER(FFont::FindFont(name)); +} + +static int GetCharWidth(FFont *font, int code) +{ + return font->GetCharWidth(code); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FFont, GetCharWidth, GetCharWidth) +{ + PARAM_SELF_STRUCT_PROLOGUE(FFont); + PARAM_INT(code); + ACTION_RETURN_INT(self->GetCharWidth(code)); +} + +static int GetHeight(FFont *font) +{ + return font->GetHeight(); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FFont, GetHeight, GetHeight) +{ + PARAM_SELF_STRUCT_PROLOGUE(FFont); + ACTION_RETURN_INT(self->GetHeight()); +} + +double GetBottomAlignOffset(FFont *font, int c); +DEFINE_ACTION_FUNCTION_NATIVE(FFont, GetBottomAlignOffset, GetBottomAlignOffset) +{ + PARAM_SELF_STRUCT_PROLOGUE(FFont); + PARAM_INT(code); + ACTION_RETURN_FLOAT(GetBottomAlignOffset(self, code)); +} + +static int StringWidth(FFont *font, const FString &str) +{ + const char *txt = str[0] == '$' ? GStrings(&str[1]) : str.GetChars(); + return font->StringWidth(txt); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FFont, StringWidth, StringWidth) +{ + PARAM_SELF_STRUCT_PROLOGUE(FFont); + PARAM_STRING(str); + ACTION_RETURN_INT(StringWidth(self, str)); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FFont, FindFontColor, V_FindFontColor) +{ + PARAM_PROLOGUE; + PARAM_NAME(code); + ACTION_RETURN_INT((int)V_FindFontColor(code)); +} + +static void GetCursor(FFont *font, FString *result) +{ + *result = font->GetCursor(); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FFont, GetCursor, GetCursor) +{ + PARAM_SELF_STRUCT_PROLOGUE(FFont); + ACTION_RETURN_STRING(FString(self->GetCursor())); +} + +//===================================================================================== +// +// AActor exports (this will be expanded) +// +//===================================================================================== + DEFINE_ACTION_FUNCTION_NATIVE(AActor, A_PlaySound, A_PlaySound) { PARAM_SELF_PROLOGUE(AActor); diff --git a/src/v_font.cpp b/src/v_font.cpp index 3a589e7413..eed94341b8 100644 --- a/src/v_font.cpp +++ b/src/v_font.cpp @@ -336,14 +336,6 @@ FFont *V_GetFont(const char *name) return font; } -DEFINE_ACTION_FUNCTION(FFont, GetFont) -{ - PARAM_PROLOGUE; - PARAM_NAME(name); - ACTION_RETURN_POINTER(V_GetFont(name.GetChars())); -} - - //========================================================================== // // FFont :: FFont @@ -528,13 +520,6 @@ FFont *FFont::FindFont (FName name) return nullptr; } -DEFINE_ACTION_FUNCTION(FFont, FindFont) -{ - PARAM_PROLOGUE; - PARAM_NAME(name); - ACTION_RETURN_POINTER(FFont::FindFont(name)); -} - //========================================================================== // // RecordTextureColors @@ -856,17 +841,21 @@ int FFont::GetCharWidth (int code) const return (code < 0) ? SpaceWidth : Chars[code - FirstChar].XMove; } -DEFINE_ACTION_FUNCTION(FFont, GetCharWidth) -{ - PARAM_SELF_STRUCT_PROLOGUE(FFont); - PARAM_INT(code); - ACTION_RETURN_INT(self->GetCharWidth(code)); -} +//========================================================================== +// +// +// +//========================================================================== -DEFINE_ACTION_FUNCTION(FFont, GetHeight) +double GetBottomAlignOffset(FFont *font, int c) { - PARAM_SELF_STRUCT_PROLOGUE(FFont); - ACTION_RETURN_INT(self->GetHeight()); + int w; + FTexture *tex_zero = font->GetChar('0', &w); + FTexture *texc = font->GetChar(c, &w); + double offset = 0; + if (texc) offset += texc->GetScaledTopOffsetDouble(0); + if (tex_zero) offset += -tex_zero->GetScaledTopOffsetDouble(0) + tex_zero->GetScaledHeightDouble(); + return offset; } //========================================================================== @@ -914,15 +903,6 @@ int FFont::StringWidth(const uint8_t *string) const return MAX(maxw, w); } -DEFINE_ACTION_FUNCTION(FFont, StringWidth) -{ - PARAM_SELF_STRUCT_PROLOGUE(FFont); - PARAM_STRING(str); - const char *txt = str[0] == '$' ? GStrings(&str[1]) : str.GetChars(); - - ACTION_RETURN_INT(self->StringWidth(txt)); -} - //========================================================================== // // FFont :: LoadTranslations @@ -2540,13 +2520,6 @@ EColorRange V_FindFontColor (FName name) return CR_UNTRANSLATED; } -DEFINE_ACTION_FUNCTION(FFont, FindFontColor) -{ - PARAM_PROLOGUE; - PARAM_NAME(code); - ACTION_RETURN_INT((int)V_FindFontColor(code)); -} - //========================================================================== // // V_LogColorFromColorRange @@ -2721,8 +2694,3 @@ void V_ClearFonts() SmallFont = SmallFont2 = BigFont = ConFont = IntermissionFont = NULL; } -DEFINE_ACTION_FUNCTION(FFont, GetCursor) -{ - PARAM_SELF_STRUCT_PROLOGUE(FFont); - ACTION_RETURN_STRING(FString(self->GetCursor())); -} diff --git a/src/v_video.h b/src/v_video.h index f54092509f..1cba846f02 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -218,7 +218,6 @@ enum DTA_SrcHeight, DTA_LegacyRenderStyle, // takes an old-style STYLE_* constant instead of an FRenderStyle DTA_Burn, // activates the burn shader for this element - }; enum