From 3758e3e1fab481baaf9117a10aab104453e69391 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 29 Nov 2018 19:41:03 +0100 Subject: [PATCH] Add direct native calls to TexMan's native methods. # Conflicts: # src/textures/texturemanager.cpp --- src/dthinker.cpp | 7 ++- src/r_utility.cpp | 20 +++++-- src/textures/texturemanager.cpp | 99 +++++++++++++++++++++++---------- 3 files changed, 92 insertions(+), 34 deletions(-) diff --git a/src/dthinker.cpp b/src/dthinker.cpp index cb9807640..b28b7af5a 100644 --- a/src/dthinker.cpp +++ b/src/dthinker.cpp @@ -395,7 +395,12 @@ void DThinker::ChangeStatNum (int statnum) list->AddTail(this); } -DEFINE_ACTION_FUNCTION(DThinker, ChangeStatNum) +static void ChangeStatNum(DThinker *thinker, int statnum) +{ + thinker->ChangeStatNum(statnum); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DThinker, ChangeStatNum, ChangeStatNum) { PARAM_SELF_PROLOGUE(DThinker); PARAM_INT(stat); diff --git a/src/r_utility.cpp b/src/r_utility.cpp index 650f7ed49..d518b69f4 100644 --- a/src/r_utility.cpp +++ b/src/r_utility.cpp @@ -1056,15 +1056,27 @@ void FCanvasTextureInfo::Add (AActor *viewpoint, FTextureID picnum, double fov) } // [ZZ] expose this to ZScript -DEFINE_ACTION_FUNCTION(_TexMan, SetCameraToTexture) +void SetCameraToTexture(AActor *viewpoint, const FString &texturename, double fov) +{ + FTextureID textureid = TexMan.CheckForTexture(texturename, ETextureType::Wall, FTextureManager::TEXMAN_Overridable); + if (textureid.isValid()) + { + // Only proceed if the texture actually has a canvas. + FTexture *tex = TexMan[textureid]; + if (tex && tex->bHasCanvas) + { + FCanvasTextureInfo::Add(viewpoint, textureid, fov); + } + } +} + +DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, SetCameraToTexture, SetCameraToTexture) { PARAM_PROLOGUE; PARAM_OBJECT(viewpoint, AActor); PARAM_STRING(texturename); // [ZZ] there is no point in having this as FTextureID because it's easier to refer to a cameratexture by name and it isn't executed too often to cache it. PARAM_FLOAT(fov); - FTextureID textureid = TexMan.CheckForTexture(texturename, ETextureType::Wall, FTextureManager::TEXMAN_Overridable); - if (textureid.isValid()) - FCanvasTextureInfo::Add(viewpoint, textureid, fov); + SetCameraToTexture(viewpoint, texturename, fov); return 0; } diff --git a/src/textures/texturemanager.cpp b/src/textures/texturemanager.cpp index ab5d830d2..c68b1a252 100644 --- a/src/textures/texturemanager.cpp +++ b/src/textures/texturemanager.cpp @@ -257,13 +257,18 @@ FTextureID FTextureManager::CheckForTexture (const char *name, ETextureType uset return FTextureID(-1); } -DEFINE_ACTION_FUNCTION(_TexMan, CheckForTexture) +static int CheckForTexture(const FString &name, int type, int flags) +{ + return TexMan.CheckForTexture(name, static_cast(type), flags).GetIndex(); +} + +DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, CheckForTexture, CheckForTexture) { PARAM_PROLOGUE; PARAM_STRING(name); PARAM_INT(type); PARAM_INT(flags); - ACTION_RETURN_INT(TexMan.CheckForTexture(name, static_cast(type), flags).GetIndex()); + ACTION_RETURN_INT(CheckForTexture(name, type, flags)); } //========================================================================== @@ -1239,10 +1244,8 @@ DEFINE_ACTION_FUNCTION(_TexMan, GetName) // //========================================================================== -DEFINE_ACTION_FUNCTION(_TexMan, GetSize) +static void GetTextureSize(int texid, int *px, int *py) { - PARAM_PROLOGUE; - PARAM_INT(texid); auto tex = TexMan.ByIndex(texid); int x, y; if (tex != nullptr) @@ -1251,6 +1254,16 @@ DEFINE_ACTION_FUNCTION(_TexMan, GetSize) y = tex->GetHeight(); } else x = y = -1; + if (px) *px = x; + if (py) *py = y; +} + +DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, GetSize, GetTextureSize) +{ + PARAM_PROLOGUE; + PARAM_INT(texid); + int x, y; + GetTextureSize(texid, &x, &y); if (numret > 0) ret[0].SetInt(x); if (numret > 1) ret[1].SetInt(y); return MIN(numret, 2); @@ -1261,17 +1274,61 @@ DEFINE_ACTION_FUNCTION(_TexMan, GetSize) // // //========================================================================== +static void GetScaledSize(int texid, DVector2 *pvec) +{ + auto tex = TexMan.ByIndex(texid); + int x, y; + if (tex != nullptr) + { + x = tex->GetScaledWidthDouble(); + y = tex->GetScaledHeightDouble(); + } + else x = y = -1; + if (pvec) + { + pvec->X = x; + pvec->Y = y; + } +} -DEFINE_ACTION_FUNCTION(_TexMan, GetScaledSize) +DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, GetScaledSize, GetScaledSize) { PARAM_PROLOGUE; PARAM_INT(texid); + DVector2 vec; + GetScaledSize(texid, &vec); + ACTION_RETURN_VEC2(vec); +} + +//========================================================================== +// +// +// +//========================================================================== +static void GetScaledOffset(int texid, DVector2 *pvec) +{ auto tex = TexMan.ByIndex(texid); + int x, y; if (tex != nullptr) { - ACTION_RETURN_VEC2(DVector2(tex->GetScaledWidthDouble(), tex->GetScaledHeightDouble())); + x = tex->GetScaledLeftOffsetDouble(); + y = tex->GetScaledTopOffsetDouble(); } - ACTION_RETURN_VEC2(DVector2(-1, -1)); + else x = y = -1; + if (pvec) + { + pvec->X = x; + pvec->Y = y; + } +} + +DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, GetScaledOffset, GetScaledOffset) +{ + PARAM_PROLOGUE; + PARAM_INT(texid); + DVector2 vec; + GetScaledOffset(texid, &vec); + ACTION_RETURN_VEC2(vec); } //========================================================================== @@ -1280,34 +1337,18 @@ DEFINE_ACTION_FUNCTION(_TexMan, GetScaledSize) // //========================================================================== -DEFINE_ACTION_FUNCTION(_TexMan, GetScaledOffset) +static int CheckRealHeight(int texid) { - PARAM_PROLOGUE; - PARAM_INT(texid); auto tex = TexMan.ByIndex(texid); - if (tex != nullptr) - { - ACTION_RETURN_VEC2(DVector2(tex->GetScaledLeftOffsetDouble(), tex->GetScaledTopOffsetDouble())); - } - ACTION_RETURN_VEC2(DVector2(-1, -1)); + if (tex != nullptr) return tex->CheckRealHeight(); + else return -1; } -//========================================================================== -// -// -// -//========================================================================== - -DEFINE_ACTION_FUNCTION(_TexMan, CheckRealHeight) +DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, CheckRealHeight, CheckRealHeight) { PARAM_PROLOGUE; PARAM_INT(texid); - auto tex = TexMan.ByIndex(texid); - if (tex != nullptr) - { - ACTION_RETURN_INT(tex->CheckRealHeight()); - } - ACTION_RETURN_INT(-1); + ACTION_RETURN_INT(CheckRealHeight(texid)); } //==========================================================================