Skip to content

Commit

Permalink
Remove deprecated Bresenham functions
Browse files Browse the repository at this point in the history
  • Loading branch information
HexDecimal committed Nov 9, 2024
1 parent d80f6f8 commit 5fd77d8
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 195 deletions.
7 changes: 0 additions & 7 deletions docs/base-toolkits/line_drawing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,3 @@ Callback-based line drawing

.. doxygenclass:: tcod::BresenhamLine
:members:

Deprecated functions
^^^^^^^^^^^^^^^^^^^^

.. doxygenfunction:: TCODFOV_line_mt
.. doxygenfunction:: TCODFOV_line_init
.. doxygenfunction:: TCODFOV_line_step
12 changes: 0 additions & 12 deletions include/libtcod-fov/bresenham.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ extern "C" {
*/
typedef bool (*TCODFOV_line_listener_t)(int x, int y);

TCODFOV_PUBLIC
TCODFOV_DEPRECATED("This function is not reentrant. Use TCODFOV_line_init_mt instead.")
void TCODFOV_line_init(int xFrom, int yFrom, int xTo, int yTo);

/** advance one step. returns true if we reach destination */
TCODFOV_PUBLIC TCODFOV_DEPRECATED("This function is not reentrant.") bool TCODFOV_line_step(
int* __restrict xCur, int* __restrict yCur);

/* atomic callback function. Stops when the callback returns false */
TCODFOV_PUBLIC bool TCODFOV_line(int xFrom, int yFrom, int xTo, int yTo, TCODFOV_line_listener_t listener);
/**
Expand All @@ -82,10 +74,6 @@ TCODFOV_PUBLIC void TCODFOV_line_init_mt(int xFrom, int yFrom, int xTo, int yTo,
TCODFOV_PUBLIC bool TCODFOV_line_step_mt(
int* __restrict xCur, int* __restrict yCur, TCODFOV_bresenham_data_t* __restrict data);

TCODFOV_DEPRECATED("Use TCODFOV_line instead.")
TCODFOV_PUBLIC bool TCODFOV_line_mt(
int xFrom, int yFrom, int xTo, int yTo, TCODFOV_line_listener_t listener, TCODFOV_bresenham_data_t* data);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
Expand Down
109 changes: 0 additions & 109 deletions include/libtcod-fov/bresenham.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,115 +40,6 @@

#include "bresenham.h"

// clang-format off
class TCODFOV_PUBLIC TCODLineListener {
public :
virtual bool putPoint(int x,int y) = 0;
virtual ~TCODLineListener() {}
};

class TCODFOV_PUBLIC TCODLine {
public :
/**
@PageName line
@PageCategory Base toolkits
@PageTitle Line drawing toolkit
@PageDesc This toolkit is a very simple and lightweight implementation of the bresenham line drawing algorithm. It allows you to follow straight paths on your map very easily.
@FuncTitle Initializing the line
@FuncDesc First, you have to initialize the toolkit with your starting and ending coordinates.
@Cpp static void TCODLine::init (int xFrom, int yFrom, int xTo, int yTo)
@C void TCODFOV_line_init (int xFrom, int yFrom, int xTo, int yTo)
@Py line_init (xFrom, yFrom, xTo, yTo)
@C# static void TCODLine::init(int xFrom, int yFrom, int xTo, int yTo)
@Lua tcod.line.init(xFrom,yFrom, xTo,yTo)
@Param xFrom,yFrom Coordinates of the line's starting point.
@Param xTo,yTo Coordinates of the line's ending point.
*/
static void init(int xFrom, int yFrom, int xTo, int yTo);

/**
@PageName line
@FuncTitle Walking the line
@FuncDesc You can then step through each cell with this function. It returns true when you reach the line's ending point.
@Cpp static bool TCODLine::step (int * xCur, int * yCur)
@C bool TCODFOV_line_step (int * xCur, int * yCur)
@Py line_step () # returns x,y or None,None if finished
@C# static bool TCODLine::step(ref int xCur, ref int yCur)
@Lua tcod.line.step(x,y) -- returns lineEnd,x,y
@Param xCur,yCur the coordinates of the next cell on the line are stored here when the function returns
@CppEx
// Going from point 5,8 to point 13,4
int x = 5, y = 8;
TCODLine::init(x,y,13,4);
do {
// update cell x,y
} while (!TCODLine::step(&x,&y));
@CEx
int x = 5, y = 8;
TCODFOV_line_init(x,y,13,4);
do {
// update cell x,y
} while (!TCODFOV_line_step(&x,&y));
@PyEx
libtcod.line_init(5,8,13,4)
# update cell 5,8
x,y=libtcod.line_step()
while (not x is None) :
# update cell x,y
x,y=libtcod.line_step()
@LuaEx
x=5
y=8
tcod.line.init(x,y,13,4)
repeat
-- update cell x,y
lineEnd,x,y = tcod.line.step(x,y)
until lineEnd
*/
static bool step(int *xCur, int *yCur);

/**
@PageName line
@FuncTitle Callback-based function
@FuncDesc The function returns false if the line has been interrupted by the callback (it returned false before the last point).
@Cpp
class TCODFOV_PUBLIC TCODLineListener {
virtual bool putPoint (int x, int y) = 0;
};
static bool TCODLine::line (int xFrom, int yFrom, int xTo, int yTo, TCODLineListener * listener)
@C
typedef bool (*TCODFOV_line_listener_t) (int x, int y);
bool TCODFOV_line(int xFrom, int yFrom, int xTo, int yTo, TCODFOV_line_listener_t listener)
@Py
def line_listener(x,y) : # ...
line(xFrom, yFrom, xTo, yTo, listener)
@C# static bool line(int xFrom, int yFrom, int xTo, int yTo, TCODLineListener listener)
@Param xFrom,yFrom Coordinates of the line's starting point.
@Param xTo,yTo Coordinates of the line's ending point.
@Param listener Callback called for each line's point. The function stops if the callback returns false.
@CppEx // Going from point 5,8 to point 13,4
class MyLineListener : public TCODLineListener {
public:
bool putPoint (int x,int y) {
printf ("%d %d\n",x,y);
return true;
}
};
MyLineListener myListener;
TCODLine::line(5,8,13,4,&myListener);
@CEx bool my_listener(int x,int y) {
printf ("%d %d\n",x,y);
return true;
}
TCODFOV_line_line(5,8,13,4,my_listener);
@PyEx def my_listener(x,y):
print x,y
return True
libtcod.line_line(5,8,13,4,my_listener)
*/
static bool line(int xFrom, int yFrom, int xTo, int yTo, TCODLineListener *listener);
};
// clang-format on
namespace tcod {
/**
Encapsulates a Bresenham line drawing algorithm.
Expand Down
72 changes: 5 additions & 67 deletions src/libtcod-fov/bresenham_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
* \file bresenham_c.c
* \brief bresenham line drawing
*/
/* This static variable is deprecated since 1.6 */
static TCODFOV_bresenham_data_t bresenham_data;
/**
* \brief Initialize a TCODFOV_bresenham_data_t struct.
*
Expand Down Expand Up @@ -110,70 +108,6 @@ bool TCODFOV_line_step_mt(int* __restrict xCur, int* __restrict yCur, TCODFOV_br
*yCur = data->origy;
return false;
}
/**
* \brief Iterate over a line using a callback.
*
* \param xo The origin x position.
* \param yo The origin y position.
* \param xd The destination x position.
* \param yd The destination y position.
* \param listener A TCODFOV_line_listener_t callback.
* \param data Pointer to a TCODFOV_bresenham_data_t struct.
* \return true if the line was completely exhausted by the callback.
*
* \verbatim embed:rst:leading-asterisk
* .. deprecated:: 1.6.6
* The `data` parameter for this call is redundant, you should call
* :any:`TCODFOV_line` instead.
* \endverbatim
*/
bool TCODFOV_line_mt(int xo, int yo, int xd, int yd, TCODFOV_line_listener_t listener, TCODFOV_bresenham_data_t* data) {
TCODFOV_line_init_mt(xo, yo, xd, yd, data);
do {
if (!listener(xo, yo)) return false;
} while (!TCODFOV_line_step_mt(&xo, &yo, data));
return true;
}
/**
* \brief Initialize a line using a global state.
*
* \param xFrom The starting x position.
* \param yFrom The starting y position.
* \param xTo The ending x position.
* \param yTo The ending y position.
*
* \verbatim embed:rst:leading-asterisk
* .. deprecated:: 1.6.6
* This function is not reentrant and will fail if a new line is started
* before the last is finished processing.
*
* Use :any:`TCODFOV_line_init_mt` instead.
* \endverbatim
*/
void TCODFOV_line_init(int xFrom, int yFrom, int xTo, int yTo) {
TCODFOV_line_init_mt(xFrom, yFrom, xTo, yTo, &bresenham_data);
}
/**
* \brief Get the next point in a line, returns true once the line has ended.
*
* \param xCur An int pointer to fill with the next x position.
* \param yCur An int pointer to fill with the next y position.
* \return true once the ending point has been reached.
*
* The starting point is excluded by this function.
* After the ending point is reached, the next call will return true.
*
* \verbatim embed:rst:leading-asterisk
* .. deprecated:: 1.6.6
* This function is not reentrant and will fail if a new line is started
* before the last is finished processing.
*
* Use :any:`TCODFOV_line_step_mt` instead.
* \endverbatim
*/
bool TCODFOV_line_step(int* __restrict xCur, int* __restrict yCur) {
return TCODFOV_line_step_mt(xCur, yCur, &bresenham_data);
}
/**
* \brief Iterate over a line using a callback.
*
Expand All @@ -191,5 +125,9 @@ bool TCODFOV_line_step(int* __restrict xCur, int* __restrict yCur) {
*/
bool TCODFOV_line(int xo, int yo, int xd, int yd, TCODFOV_line_listener_t listener) {
TCODFOV_bresenham_data_t data;
return TCODFOV_line_mt(xo, yo, xd, yd, listener, &data);
TCODFOV_line_init_mt(xo, yo, xd, yd, &data);
do {
if (!listener(xo, yo)) return false;
} while (!TCODFOV_line_step_mt(&xo, &yo, &data));
return true;
}

0 comments on commit 5fd77d8

Please sign in to comment.