Add direct native calls to TexMan's native methods.

This commit is contained in:
Christoph Oelckers 2018-11-29 19:41:03 +01:00
parent ba2b9430f8
commit 3ecda35379
3 changed files with 92 additions and 34 deletions

View File

@ -392,7 +392,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);

View File

@ -1100,15 +1100,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;
}

View File

@ -260,13 +260,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<ETextureType>(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<ETextureType>(type), flags).GetIndex());
ACTION_RETURN_INT(CheckForTexture(name, type, flags));
}
//==========================================================================
@ -1412,10 +1417,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)
@ -1424,6 +1427,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);
@ -1434,17 +1447,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(0);
y = tex->GetScaledTopOffsetDouble(0);
}
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);
}
//==========================================================================
@ -1453,34 +1510,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(0), tex->GetScaledTopOffsetDouble(0)));
}
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));
}
//==========================================================================