Commit a4a0ec95 authored by Michael Natterer's avatar Michael Natterer 😴

plug-ins, pdb: remove the maze plug-in and add a PDB compat proc

parent 3f02b2aa
......@@ -28,7 +28,7 @@
#include "internal-procs.h"
/* 772 procedures registered total */
/* 773 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)
......
......@@ -2397,6 +2397,73 @@ plug_in_make_seamless_invoker (GimpProcedure *procedure,
error ? *error : NULL);
}
static GimpValueArray *
plug_in_maze_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpDrawable *drawable;
gint16 width;
gint16 height;
guint8 tileable;
guint8 algorithm;
gint32 seed;
drawable = gimp_value_get_drawable (gimp_value_array_index (args, 2), gimp);
width = g_value_get_int (gimp_value_array_index (args, 3));
height = g_value_get_int (gimp_value_array_index (args, 4));
tileable = g_value_get_uint (gimp_value_array_index (args, 5));
algorithm = g_value_get_uint (gimp_value_array_index (args, 6));
seed = g_value_get_int (gimp_value_array_index (args, 7));
if (success)
{
if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
GIMP_PDB_ITEM_CONTENT, error) &&
gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
{
GeglNode *node;
GeglColor *fg_color;
GeglColor *bg_color;
GimpRGB color;
gimp_context_get_foreground (context, &color);
fg_color = gimp_gegl_color_new (&color);
gimp_context_get_background (context, &color);
bg_color = gimp_gegl_color_new (&color);
node = gegl_node_new_child (NULL,
"operation", "gegl:maze",
"x", width,
"y", height,
"algorithm-type", algorithm,
"tilable", tileable,
"seed", seed,
"fg-color", fg_color,
"bg-color", bg_color,
NULL);
g_object_unref (fg_color);
g_object_unref (bg_color);
gimp_drawable_apply_operation (drawable, progress,
C_("undo-type", "Maze"),
node);
g_object_unref (node);
}
else
success = FALSE;
}
return gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static GimpValueArray *
plug_in_mblur_invoker (GimpProcedure *procedure,
Gimp *gimp,
......@@ -6452,6 +6519,84 @@ register_plug_in_compat_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-plug-in-maze
*/
procedure = gimp_procedure_new (plug_in_maze_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"plug-in-maze");
gimp_procedure_set_static_strings (procedure,
"plug-in-maze",
"Draw a labyrinth",
"Generates a maze using either the depth-first search method or Prim's algorithm. Can make tileable mazes too.",
"Compatibility procedure. Please see 'gegl:maze' for credits.",
"Compatibility procedure. Please see 'gegl:maze' for credits.",
"2015",
NULL);
gimp_procedure_add_argument (procedure,
g_param_spec_enum ("run-mode",
"run mode",
"The run mode",
GIMP_TYPE_RUN_MODE,
GIMP_RUN_INTERACTIVE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_image_id ("image",
"image",
"Input image (unused)",
pdb->gimp, FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_drawable_id ("drawable",
"drawable",
"Input drawable",
pdb->gimp, FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_int16 ("width",
"width",
"Width of the passages",
1, 1024, 1,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_int16 ("height",
"height",
"Height of the passages",
1, 1024, 1,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_int8 ("tileable",
"tileable",
"Tileable maze? (TRUE or FALSE)",
0, 1, 0,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_int8 ("algorithm",
"algorithm",
"Generation algorithm (0 = DEPTH FIRST, 1 = PRIM'S ALGORITHM)",
0, 1, 0,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_int32 ("seed",
"seed",
"Random Seed",
G_MININT32, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_int16 ("multiple",
"multiple",
"Multiple (use 57)",
G_MININT16, G_MAXINT16, 0,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_int16 ("offset",
"offset",
"Offset (use 1)",
G_MININT16, G_MAXINT16, 0,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-plug-in-mblur
*/
......
......@@ -2312,7 +2312,6 @@ plug-ins/imagemap/images/Makefile
plug-ins/lighting/Makefile
plug-ins/lighting/images/Makefile
plug-ins/map-object/Makefile
plug-ins/maze/Makefile
plug-ins/pagecurl/Makefile
plug-ins/print/Makefile
plug-ins/pygimp/Makefile
......
......@@ -52,7 +52,6 @@ SUBDIRS = \
imagemap \
lighting \
map-object \
maze \
pagecurl \
$(print) \
selection-to-path \
......
/Makefile.in
/Makefile
/.deps
/_libs
/.libs
/maze
/maze.exe
## Process this file with automake to produce Makefile.in
libgimpui = $(top_builddir)/libgimp/libgimpui-$(GIMP_API_VERSION).la
libgimpconfig = $(top_builddir)/libgimpconfig/libgimpconfig-$(GIMP_API_VERSION).la
libgimpwidgets = $(top_builddir)/libgimpwidgets/libgimpwidgets-$(GIMP_API_VERSION).la
libgimp = $(top_builddir)/libgimp/libgimp-$(GIMP_API_VERSION).la
libgimpcolor = $(top_builddir)/libgimpcolor/libgimpcolor-$(GIMP_API_VERSION).la
libgimpbase = $(top_builddir)/libgimpbase/libgimpbase-$(GIMP_API_VERSION).la
libgimpmath = $(top_builddir)/libgimpmath/libgimpmath-$(GIMP_API_VERSION).la
if OS_WIN32
mwindows = -mwindows
endif
if HAVE_WINDRES
include $(top_srcdir)/build/windows/gimprc-plug-ins.rule
maze_RC = maze.rc.o
endif
AM_LDFLAGS = $(mwindows)
libexecdir = $(gimpplugindir)/plug-ins
libexec_PROGRAMS = maze
maze_SOURCES = \
maze.c \
maze.h \
maze-algorithms.c \
maze-algorithms.h \
maze-dialog.c \
maze-dialog.h \
maze-utils.c \
maze-utils.h
AM_CPPFLAGS = \
-I$(top_srcdir) \
$(GTK_CFLAGS) \
$(GEGL_CFLAGS) \
-I$(includedir)
LDADD = \
$(libgimpui) \
$(libgimpwidgets) \
$(libgimpconfig) \
$(libgimp) \
$(libgimpcolor) \
$(libgimpmath) \
$(libgimpbase) \
$(GTK_LIBS) \
$(RT_LIBS) \
$(INTLLIBS) \
$(maze_RC)
/* $Id$
* Contains routines for generating mazes, somewhat intertwined with
* Gimp plug-in-maze specific stuff.
*
* Kevin Turner <acapnotic@users.sourceforge.net>
* http://gimp-plug-ins.sourceforge.net/maze/
*/
/* mazegen code from rec.games.programmer's maze-faq:
* * maz.c - generate a maze
* *
* * algorithm posted to rec.games.programmer by jallen@ic.sunysb.edu
* * program cleaned and reorganized by mzraly@ldbvax.dnet.lotus.com
* *
* * don't make people pay for this, or I'll jump up and down and
* * yell and scream and embarrass you in front of your friends...
*/
/* I've put a HTMLized version of the FAQ up at
* http://www.poboxes.com/kevint/gimp/maze-faq/maze-faq.html
*/
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "config.h"
#include <stdlib.h>
#include "libgimp/gimp.h"
#include "maze.h"
#include "maze-algorithms.h"
#include "libgimp/stdplugins-intl.h"
#define ABSMOD(A,B) (((A) < 0) ? (((B) + (A)) % (B)) : ((A) % (B)))
/* Since we are using a 1D array on 2D space, we need to do our own
calculations. (Ok, so there are ways of doing dynamically allocated
2D arrays, but we started this way, so let's stick with it. */
/* The difference between CELL_* and WALL_* is that cell moves two spaces,
while wall moves one. */
/* Macros assume that x and y will be defined where they are used. */
/* A return of -1 means "no such place, don't go there". */
#define CELL_UP(POS) ((POS) < (x*2) ? -1 : (POS) - x - x)
#define CELL_DOWN(POS) ((POS) >= x*(y-2) ? -1 : (POS) + x + x)
#define CELL_LEFT(POS) (((POS) % x) <= 1 ? -1 : (POS) - 2)
#define CELL_RIGHT(POS) (((POS) % x) >= (x - 2) ? -1 : (POS) + 2)
/* With walls, we don't need to check for boundaries, since we are
assured that there *is* a valid cell on the other side of the
wall. */
#define WALL_UP(POS) ((POS) - x)
#define WALL_DOWN(POS) ((POS) + x)
#define WALL_LEFT(POS) ((POS) - 1)
#define WALL_RIGHT(POS) ((POS) + 1)
/***** For tileable mazes *****/
#define CELL_UP_TILEABLE(POS) ((POS) < (x*2) ? x*(y-2)+(POS) : (POS) - x - x)
#define CELL_DOWN_TILEABLE(POS) ((POS) >= x*(y-2) ? (POS) - x*(y-2) : (POS) + x + x)
#define CELL_LEFT_TILEABLE(POS) (((POS) % x) <= 1 ? (POS) + x - 2 : (POS) - 2)
#define CELL_RIGHT_TILEABLE(POS) (((POS) % x) >= (x - 2) ? (POS) + 2 - x : (POS) + 2)
/* Up and left need checks, but down and right should never have to
wrap on an even sized maze. */
#define WALL_UP_TILEABLE(POS) ((POS) < x ? x*(y-1)+(POS) : (POS) - x)
#define WALL_DOWN_TILEABLE(POS) ((POS) + x)
#define WALL_LEFT_TILEABLE(POS) (((POS) % x) == 0 ? (POS) + x - 1 : (POS) - 1)
#define WALL_RIGHT_TILEABLE(POS) ((POS) + 1)
/* Down and right with checks.
#define WALL_DOWN_TILEABLE(POS) ((POS) >= x*(y-1) ? (POS) - x * (y-1) : (POS) + x)
#define WALL_RIGHT_TILEABLE(POS) (((POS) % x) == (x - 1) ? (POS) + 1 - x : (POS) + 1)
*/
/* The Incredible Recursive Maze Generation Routine */
/* Ripped from rec.programmers.games maze-faq */
/* Modified and commented by me, Kevin Turner. */
void
mazegen (gint pos,
guchar *maz,
gint x,
gint y,
gint rnd)
{
gchar d, i;
gint c = 0;
gint j = 1;
/* Punch a hole here... */
maz[pos] = IN;
/* If there is a wall two rows above us, bit 1 is 1. */
while ((d= (pos <= (x * 2) ? 0 : (maz[pos - x - x ] ? 0 : 1))
/* If there is a wall two rows below us, bit 2 is 1. */
| (pos >= x * (y - 2) ? 0 : (maz[pos + x + x] ? 0 : 2))
/* If there is a wall two columns to the right, bit 3 is 1. */
| (pos % x == x - 2 ? 0 : (maz[pos + 2] ? 0 : 4))
/* If there is a wall two colums to the left, bit 4 is 1. */
| ((pos % x == 1 ) ? 0 : (maz[pos-2] ? 0 : 8))))
{
/* Note if all bits are 0, d is false, we don't do this
while loop, we don't call ourselves again, so this branch
is done. */
/* I see what this loop does (more or less), but I don't know
_why_ it does it this way... I also haven't figured out exactly
which values of multiple will work and which won't. */
do
{
rnd = (rnd * mvals.multiple + mvals.offset);
i = 3 & (rnd / d);
if (++c > 100)
{ /* Break and try to salvage something */
i=99; /* if it looks like we're going to be */
break; /* here forever... */
}
}
while (!(d & (1 << i)));
/* ...While there's *not* a wall in direction i. */
/* (stop looping when there is) */
switch (i)
{
case 0: /* Go in the direction we just figured . . . */
j = -x;
break;
case 1:
j = x;
break;
case 2:
j = 1;
break;
case 3:
j = -1;
break;
case 99:
return; /* Hey neat, broken mazes! */
break; /* (Umm... Wow... Yeah, neat.) */
default:
g_warning ("maze: mazegen: Going in unknown direction.\n"
"i: %d, d: %d, seed: %d, mw: %d, mh: %d, mult: %d, offset: %d\n",
i, d,mvals.seed, x, y, mvals.multiple, mvals.offset);
break;
}
/* And punch a hole there. */
maz[pos + j] = 1;
/* Now, start again just past where we punched the hole... */
mazegen (pos + 2 * j, maz, x, y, rnd);
}
return;
}
/* Tileable mazes are my creation, based on the routine above. */
void
mazegen_tileable (gint pos,
guchar *maz,
gint x,
gint y,
gint rnd)
{
gchar d, i;
gint c = 0;
gint npos = 2;
/* Punch a hole here... */
maz[pos] = IN;
/* If there is a wall two rows above us, bit 1 is 1. */
while ((d= (maz[CELL_UP_TILEABLE(pos)] ? 0 : 1)
/* If there is a wall two rows below us, bit 2 is 1. */
| (maz[CELL_DOWN_TILEABLE(pos)] ? 0 : 2)
/* If there is a wall two columns to the right, bit 3 is 1. */
| (maz[CELL_RIGHT_TILEABLE(pos)] ? 0 : 4)
/* If there is a wall two colums to the left, bit 4 is 1. */
| (maz[CELL_LEFT_TILEABLE(pos)] ? 0 : 8)))
{
/* Note if all bits are 0, d is false, we don't do this
while loop, we don't call ourselves again, so this branch
is done. */
/* I see what this loop does (more or less), but I don't know
_why_ it does it this way... I also haven't figured out exactly
which values of multiple will work and which won't. */
do
{
rnd = (rnd * mvals.multiple + mvals.offset);
i = 3 & (rnd / d);
if (++c > 100)
{ /* Break and try to salvage something */
i=99; /* if it looks like we're going to be */
break; /* here forever... */
}
}
while (!(d & (1 << i)));
/* ...While there's *not* a wall in direction i. */
/* (stop looping when there is) */
switch (i)
{
case 0: /* Go in the direction we just figured . . . */
maz[WALL_UP_TILEABLE (pos)] = IN;
npos = CELL_UP_TILEABLE (pos);
break;
case 1:
maz[WALL_DOWN_TILEABLE (pos)] = IN;
npos = CELL_DOWN_TILEABLE (pos);
break;
case 2:
maz[WALL_RIGHT_TILEABLE (pos)] = IN;
npos = CELL_RIGHT_TILEABLE (pos);
break;
case 3:
maz[WALL_LEFT_TILEABLE (pos)] = IN;
npos = CELL_LEFT_TILEABLE (pos);
break;
case 99:
return; /* Hey neat, broken mazes! */
break; /* (Umm... Wow... Yeah, neat.) */
default:
g_warning ("maze: mazegen_tileable: Going in unknown direction.\n"
"i: %d, d: %d, seed: %d, mw: %d, mh: %d, mult: %d, offset: %d\n",
i, d,mvals.seed, x, y, mvals.multiple, mvals.offset);
break;
}
/* Now, start again just past where we punched the hole... */
mazegen_tileable (npos, maz, x, y, rnd);
}
return;
}
/* This function (as well as prim_tileable) make use of the somewhat
unclean practice of storing ints as pointers. I've been informed
that this may cause problems with 64-bit stuff. However, hopefully
it will be okay, since the only values stored are positive. If it
does break, let me know, and I'll go cry in a corner for a while
before I get up the strength to re-code it. */
void
prim (gint pos,
guchar *maz,
guint x,
guint y)
{
GSList *front_cells = NULL;
guint current;
gint up, down, left, right; /* Not unsigned, because macros return -1. */
guint progress = 0;
guint max_progress;
char d, i;
guint c = 0;
gint rnd = mvals.seed;
g_rand_set_seed (gr, rnd);
gimp_progress_init (_("Constructing maze using Prim's Algorithm"));
/* OUT is zero, so we should be already initalized. */
max_progress = x * y / 4;
/* Starting position has already been determined by the calling function. */
maz[pos] = IN;
/* For now, repeating everything four times seems manageable. But when
Gimp is extended to drawings in n-dimensional space instead of 2D,
this will require a bit of a re-write. */
/* Add frontier. */
up = CELL_UP (pos);
down = CELL_DOWN (pos);
left = CELL_LEFT (pos);
right = CELL_RIGHT (pos);
if (up >= 0)
{
maz[up] = FRONTIER;
front_cells = g_slist_append (front_cells, GINT_TO_POINTER (up));
}
if (down >= 0)
{
maz[down] = FRONTIER;
front_cells = g_slist_append (front_cells, GINT_TO_POINTER (down));
}
if (left >= 0)
{
maz[left] = FRONTIER;
front_cells = g_slist_append (front_cells, GINT_TO_POINTER (left));
}
if (right >= 0)
{
maz[right] = FRONTIER;
front_cells = g_slist_append (front_cells, GINT_TO_POINTER (right));
}
/* While frontier is not empty do the following... */
while (g_slist_length (front_cells) > 0)
{
/* Remove one cell at random from frontier and place it in IN. */
current = g_rand_int_range (gr, 0, g_slist_length (front_cells));
pos = GPOINTER_TO_INT (g_slist_nth (front_cells, current)->data);
front_cells = g_slist_remove (front_cells, GINT_TO_POINTER (pos));
maz[pos] = IN;
/* If the cell has any neighbors in OUT, remove them from
OUT and place them in FRONTIER. */
up = CELL_UP (pos);
down = CELL_DOWN (pos);
left = CELL_LEFT (pos);
right = CELL_RIGHT (pos);
d = 0;
if (up >= 0)
{
switch (maz[up])
{
case OUT:
maz[up] = FRONTIER;
front_cells = g_slist_prepend (front_cells,
GINT_TO_POINTER (up));
break;
case IN:
d = 1;
break;
default:
break;
}
}
if (down >= 0)
{
switch (maz[down])
{
case OUT:
maz[down] = FRONTIER;
front_cells = g_slist_prepend (front_cells,
GINT_TO_POINTER (down));
break;
case IN:
d = d | 2;
break;
default:
break;
}
}
if (left >= 0)
{
switch (maz[left])
{
case OUT:
maz[left] = FRONTIER;
front_cells = g_slist_prepend (front_cells,
GINT_TO_POINTER (left));
break;
case IN:
d = d | 4;
break;
default:
break;
}
}
if (right >= 0)
{
switch (maz[right])
{
case OUT:
maz[right] = FRONTIER;
front_cells = g_slist_prepend (front_cells,
GINT_TO_POINTER (right));
break;
case IN:
d = d | 8;
break;
default:
break;
}
}
/* The cell is guaranteed to have at least one neighbor in
IN (otherwise it would not have been in FRONTIER); pick
one such neighbor at random and connect it to the new
cell (ie knock out a wall). */
if (!d)
{
g_warning ("maze: prim: Lack of neighbors.\n"
"seed: %d, mw: %d, mh: %d, mult: %d, offset: %d\n",
mvals.seed, x, y, mvals.multiple, mvals.offset);
break;
}
c = 0;
do
{
rnd = (rnd * mvals.multiple + mvals.offset);
i = 3 & (rnd / d);
if (++c > 100)
{ /* Break and try to salvage something */
i = 99; /* if it looks like we're going to be */
break; /* here forever... */
}
}
while (!(d & (1 << i)));
switch (i)
{
case 0:
maz[WALL_UP (pos)] = IN;
break;
case 1:
maz[WALL_DOWN (pos)] = IN;
break;
case 2:
maz[WALL_LEFT (pos)] = IN;
break;
case 3:
maz[WALL_RIGHT (pos)] = IN;
break;
case 99:
break;
default:
g_warning ("maze: prim: Going in unknown direction.\n"
"i: %d, d: %d, seed: %d, mw: %d, mh: %d, mult: %d, offset: %d\n",
i, d, mvals.seed, x, y, mvals.multiple, mvals.offset);
}
if (progress++ % PRIMS_PROGRESS_UPDATE)
gimp_progress_update ((double) progress / (double) max_progress);
}
gimp_progress_update (1.0);
g_slist_free (front_cells);
}
void
prim_tileable (guchar *maz,
guint x,
guint y)
{
GSList *front_cells=NULL;
guint current, pos;
guint up, down, left, right;
guint progress = 0;
guint max_progress;
char d, i;
guint c = 0;
gint rnd = mvals.seed;
g_rand_set_seed (gr, rnd);
gimp_progress_init (_("Constructing tileable maze using Prim's Algorithm"));