Skip to content

Commit

Permalink
Exported FBoundingBox to ZScript.
Browse files Browse the repository at this point in the history
  • Loading branch information
Doom2fan committed Dec 7, 2018
1 parent a7c4fc9 commit c41c574
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 0 deletions.
125 changes: 125 additions & 0 deletions src/m_bbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "m_bbox.h"
#include "p_local.h"
#include "p_maputl.h"
#include "vm.h"

//==========================================================================
//
Expand Down Expand Up @@ -95,3 +96,127 @@ int FBoundingBox::BoxOnLineSide (const line_t *ld) const
return (p1 == p2) ? p1 : -1;
}

class DBoundingBox : public FBoundingBox, public DObject
{
DECLARE_ABSTRACT_CLASS(DBoundingBox, DObject)

public:
DBoundingBox(double left, double bottom, double right, double top)
{
m_Box[BOXTOP] = top;
m_Box[BOXLEFT] = left;
m_Box[BOXRIGHT] = right;
m_Box[BOXBOTTOM] = bottom;
}

DBoundingBox(double x, double y, double radius)
{
setBox(x, y, radius);
}
};
IMPLEMENT_CLASS (DBoundingBox, true, false);

DEFINE_ACTION_FUNCTION(DBoundingBox, CreateFromSides)
{
PARAM_PROLOGUE;
PARAM_FLOAT(left);
PARAM_FLOAT(bottom);
PARAM_FLOAT(right);
PARAM_FLOAT(top);

ACTION_RETURN_OBJECT(Create<DBoundingBox>(left, bottom, right, top));
}

DEFINE_ACTION_FUNCTION(DBoundingBox, Create)
{
PARAM_PROLOGUE;
PARAM_FLOAT(x);
PARAM_FLOAT(y);
PARAM_FLOAT(radius);

ACTION_RETURN_OBJECT(Create<DBoundingBox>(x, y, radius));
}

DEFINE_ACTION_FUNCTION(DBoundingBox, SetBox)
{
PARAM_SELF_PROLOGUE(DBoundingBox);
PARAM_FLOAT(x);
PARAM_FLOAT(y);
PARAM_FLOAT(radius);

self->setBox(x, y, radius);
return 0;
}

DEFINE_ACTION_FUNCTION(DBoundingBox, ClearBox)
{
PARAM_SELF_PROLOGUE(DBoundingBox);

self->ClearBox();
return 0;
}

DEFINE_ACTION_FUNCTION(DBoundingBox, AddToBox)
{
PARAM_SELF_PROLOGUE(DBoundingBox);
PARAM_FLOAT(x);
PARAM_FLOAT(y);

self->AddToBox(DVector2(x, y));
return 0;
}

DEFINE_ACTION_FUNCTION(DBoundingBox, Top)
{
PARAM_SELF_PROLOGUE(DBoundingBox);

ACTION_RETURN_FLOAT(self->Top());
}

DEFINE_ACTION_FUNCTION(DBoundingBox, Bottom)
{
PARAM_SELF_PROLOGUE(DBoundingBox);

ACTION_RETURN_FLOAT(self->Bottom());
}

DEFINE_ACTION_FUNCTION(DBoundingBox, Left)
{
PARAM_SELF_PROLOGUE(DBoundingBox);

ACTION_RETURN_FLOAT(self->Left());
}

DEFINE_ACTION_FUNCTION(DBoundingBox, Right)
{
PARAM_SELF_PROLOGUE(DBoundingBox);

ACTION_RETURN_FLOAT(self->Right());
}

DEFINE_ACTION_FUNCTION(DBoundingBox, InRange)
{
PARAM_SELF_PROLOGUE(DBoundingBox);
PARAM_POINTER(line, line_t);

ACTION_RETURN_BOOL(self->inRange(line));
}

DEFINE_ACTION_FUNCTION(DBoundingBox, BoxOnLineSide)
{
PARAM_SELF_PROLOGUE(DBoundingBox);
PARAM_POINTER(line, line_t);

ACTION_RETURN_INT(self->BoxOnLineSide(line));
}

DEFINE_ACTION_FUNCTION(DBoundingBox, Set)
{
PARAM_SELF_PROLOGUE(DBoundingBox);
PARAM_INT(index);
PARAM_FLOAT(value);

self->Set(index, value);
return 0;
}

22 changes: 22 additions & 0 deletions wadsrc/static/zscript/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -996,3 +996,25 @@ struct FRailParams
native int limit;
}; // [RH] Shoot a railgun

class BoundingBox : Object native
{
native static BoundingBox CreateFromSides(double left, double bottom, double right, double top);
native static BoundingBox Create(Vector2 pos, double radius);

native void SetBox(Vector2 pos, double radius);
native void ClearBox();

native void AddToBox(Vector2 pos);

native double Top() const;
native double Bottom() const;
native double Left() const;
native double Right() const;

native bool InRange(Line ld) const;

native int BoxOnLineSide (Line ld) const;

native void Set(int index, double value);
}

9 changes: 9 additions & 0 deletions wadsrc/static/zscript/constants.txt
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,15 @@ enum EReplace
ALLOW_REPLACE = 1
}

// Bounding box coordinate storage.
enum BoundingBoxCoords
{
BOXTOP,
BOXBOTTOM,
BOXLEFT,
BOXRIGHT
};

// This translucency value produces the closest match to Heretic's TINTTAB.
// ~40% of the value of the overlaid image shows through.
const HR_SHADOW = (0x6800 / 65536.);
Expand Down

0 comments on commit c41c574

Please sign in to comment.